⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Employees Tutorial - Exception Table Not Found



George Milliken
  • profile picture
  • Member

Posted 04 May 2013 - 06:37 AM

I'm new to CI and GroceryCRUD. It looks great however after the basic installation nd verification I created the database tables, updated by database.php and cannot get the employees example to work.  Here's the error and my config:

 


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

 

My Configuration

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;
 
====================
The result of $this->db->list_tables()); in the main.php
====================
Welcome to the world of Codeigniter

Array
(
)

 

 

===================

SELECT of MySQL User table

===================

 

mysql> select host,user  from mysql.user;
+-----------+----------+
| host      | user     |
+-----------+----------+
| %         | cruduser |
| localhost | root     |
+-----------+----------+
2 rows in set (0.00 sec)
 
mysql> 
 

======================

SHOW databases in MySQL

======================

 

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| crud               |
| mysql              |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)
 
 
================
SHOW Tables in 'crud' database
================
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)
 

===================

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

DREON
  • profile picture
  • Member

Posted 04 May 2013 - 13:52 PM

read this:

 

http://www.grocerycrud.com/documentation/create-crud-codeigniter-tutorial


George Milliken
  • profile picture
  • Member

Posted 04 May 2013 - 14:49 PM

I did, that's how I got where I am and I cannot see what I've done wrong. I believe I followed the tutorial exactly.


George Milliken
  • profile picture
  • Member

Posted 04 May 2013 - 15:04 PM

I'm getting the table does not exist and when I modify the main.php to display the table list

 

 

 

echo "<pre>";
print_r($this->db->list_tables());
die();
 

 

 
I get an empty array back.

So I think maybe something is wrong with the MySQL user I configured, somehow the database is not getting selected although the database connection is successful (or I would bomb out earlier in the initialization process).

George Milliken
  • profile picture
  • Member

Posted 06 May 2013 - 14:29 PM

The answer is on Stack Overflow in this message http://stackoverflow.com/questions/7254049/codeigniter-unable-to-connect-to-your-database-server-using-the-provided-settin

 

The problem is that on OSX the /private/etc/php.ini.default must be edited and saved as php.ini with a change to the property was pointing to /var/mysql/mysql.sock but in OSX, the file was located in /tmp/mysql.sock.

 

Change this

 

mysql.default_socket = /var/mysql/mysql.sock

 
to this
 
mysql.default_socket = /tmp/mysql.sock
 
and bounce apache
 
George