我是Code Igniter和GroceryCRUD的新手。在基本安装和验证之后,我创建了数据库表并开始关注此处的新手教程。
http://www.grocerycrud.com/documentation/create-crud-codeigniter-tutorial
Fatal error: Uncaught exception Exception with message The table name does not exist.
Please check you database and try again. in /Library/WebServer/Documents/application/libraries/Grocery_CRUD.php:4349
Stack trace: #0 /Library/WebServer/Documents/application/libraries/Grocery_CRUD.php(3875):
grocery_CRUD->get_table() #1 /Library/WebServer/Documents/application/libraries/Grocery_CRUD.php(3891):
grocery_CRUD->pre_render() #2
/Library/WebServer/Documents/application/controllers/main.php(27): grocery_CRUD->render() #3
[internal function]: Main->employees() #4 /Library/WebServer/Documents/system/core/CodeIgniter.php(359): call_user_func_array(Array, Array) #5
/Library/WebServer/Documents/index.php(202): require_once(/Library/WebSer...) #6
{main} thrown in /Library/WebServer/Documents/application/libraries/Grocery_CRUD.php on line 4349
我得到的表不存在,当我修改main.php来显示表列表
echo "<pre>";
print_r($this->db->list_tables());
die();
我得到一个空数组。所以我认为我配置的MySQL用户可能有问题,虽然数据库连接成功(或者我会在初始化过程中早些时候炸弹)但数据库没有被选中。
我的配置
Mac OSX 10.7.5
database.php中
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'cruduser';
$db['default']['password'] = 'foo45bar';
$db['default']['database'] = 'crud';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = FALSE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
$ this-&gt; db-&gt; list_tables())的结果;在main.php中
欢迎来到Codeigniter的世界
Array
(
)
选择MySQL用户表
mysql> select host,user from mysql.user;
+-----------+----------+
| host | user |
+-----------+----------+
| % | cruduser |
| localhost | root |
+-----------+----------+
2 rows in set (0.00 sec)
在MySQL中显示数据库
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| crud |
| mysql |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)
在'crud'数据库中显示表
mysql> show tables;
+----------------+
| Tables_in_crud |
+----------------+
| actor |
| category |
| customers |
| employees |
| film |
| film_actor |
| film_category |
| offices |
| orderdetails |
| orders |
| payments |
| productlines |
| products |
+----------------+
13 rows in set (0.00 sec)
来自main.php的来源
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Main extends CI_Controller {
function __construct()
{
parent::__construct();
/* Standard Libraries of codeigniter are required */
$this->load->database();
$this->load->helper('url');
/* ------------------ */
$this->load->library('grocery_CRUD');
}
public function index()
{
echo "<h1>Welcome to the world of Codeigniter</h1>";//Just an example to ensure that we get into the function
echo "<pre>";
print_r($this->db->list_tables());
die();
}
public function employees()
{
$this->grocery_crud->set_table('employees');
$output = $this->grocery_crud->render();
echo "<pre>";
print_r($output);
echo "</pre>";
die();
}
}
答案 0 :(得分:0)
答案在此消息CodeIgniter: Unable to connect to your database server using the provided settings Error Message
中的Stack Overflow上问题是在OSX上必须编辑/private/etc/php.ini.default并保存为php.ini,对属性的更改指向/var/mysql/mysql.sock但在OSX中,该文件位于/tmp/mysql.sock。
更改此
mysql.default_socket = /var/mysql/mysql.sock
到这个
mysql.default_socket = /tmp/mysql.sock
并反弹apache
乔治