当我尝试连接到mysql数据库时出现此错误:
遇到PHP错误严重性:警告
消息:mysqli :: real_connect():(HY000 / 1044):拒绝用户访问 ” @“ localhost”到数据库“ calendar_events”
文件名:mysqli / mysqli_driver.php
行号:203
回溯:
文件: C:\ xampp2 \ htdocs \ fullcalendar \ application \ controllers \ Calendar.php 行:7函数:__construct
文件:C:\ xampp2 \ htdocs \ fullcalendar \ index.php行:315功能: require_once
1.index.php(视图)
<html lang="en">
<head>
<title>Calendar Display</title>
<script src="<?php echo base_url(); ?>assets/fullcalendar/lib/moment.min.js"></script>
<script src="<?php echo base_url(); ?>assets/fullcalendar/lib/jquery-ui.min.js"></script>
<script src="<?php echo base_url(); ?>assets/fullcalendar/lib/jquery.min.js"></script>
<link rel="stylesheet" href="<?php echo base_url(); ?>assets/fullcalendar/fullcalendar.min.css" />
<script src="<?php echo base_url(); ?>assets/fullcalendar/fullcalendar.min.js"></script>
<script src="<?php echo base_url(); ?>assets/fullcalendar-3.9.0/locale/es.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-12">
<h1>Calendar</h1>
<div id="calendar">
</div>
</div>
</div>
</div>
<!--<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>-->
<script type="text/javascript">
$(document).ready(function() {
$('#calendar').fullCalendar({
eventSources: [
{
events: function(start, end, timezone, callback) {
$.ajax({
url: '<?php echo base_url() ?>calendar/get_events',
dataType: 'json',
data: {
// our hypothetical feed requires UNIX timestamps
start: start.unix(),
end: end.unix()
},
success: function(msg) {
var events = msg.events;
callback(events);
}
});
}
},
]
});
});
</script>
<style>
#calendar{
width: 800px;
margin: 0px auto;
}
</style>
</body>
</html>
class Calendar_model extends CI_Model {
public function __construct()
{
parent::__construct();
$this->load->database();
}
public function get_events($start, $end){
return $this->db->where("start >=", $start)->where("end <=", $end)->get("calendar_events");
}
public function add_event($data)
{
$this->db->insert("calendar_events", $data);
}
public function get_event($id)
{
return $this->db->where("ID", $id)->get("calendar_events");
}
public function update_event($id, $data)
{
$this->db->where("ID", $id)->update("calendar_events", $data);
}
public function delete_event($id)
{
$this->db->where("ID", $id)->delete("calendar_events");
}
}
Calendar.php(控制器)
类日历扩展了CI_Controller {
public function __construct() {
parent::__construct();
$this->load->model("calendar_model");
}
public function index()
{
$this->load->helper('url');
$this->load->view('index', array());
}
public function get_events()
{
// Our Start and End Dates
$start = $this->input->get('start');
$end = $this->input->get('end');
$startdt = new DateTime('now'); // setup a local datetime
$startdt->setTimestamp($start); // Set the date based on timestamp
$start_format = $startdt->format('Y-m-d H:i:s');
$enddt = new DateTime('now'); // setup a local datetime
$enddt->setTimestamp($end); // Set the date based on timestamp
$end_format = $enddt->format('Y-m-d H:i:s');
$events = $this->calendar_model->get_events($start_format, $end_format);
$data_events = array();
foreach($events->result() as $r) {
$data_events[] = array(
"id" => $r->ID,
"title" => $r->title,
"description" => $r->description,
"end" => $r->end,
"start" => $r->start
);
}
echo json_encode(array("events" => $data_events));
exit();
}
}
答案 0 :(得分:0)
问题可能出在您显示的任何代码中。该错误消息表示您在数据库配置(localhost)中指定的用户无权使用calendar_events
数据库。
这是数据库设置问题,而不是CodeIgniter问题。
如何调整数据库用户权限取决于您可用来管理数据库的工具。
答案 1 :(得分:-1)
我认为您应该在“ application / config / database.php”中检查数据库配置。
问题可能出在此文件中。
告诉我是否可行