0

我是 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

数据库.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->db->list_tables()) 的结果;在 main.php

欢迎来到 Codeigniter 的世界

Array
(
)

MySQL用户表的SELECT

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();
    }
}
4

1 回答 1

0

答案在此消息中的 Stack Overflow 上CodeIgniter: Unable to connect to your database server using the provided settings Error Message

问题是在 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

并反弹阿帕奇

乔治

于 2013-05-06T14:30:39.523 回答