First CodeIgniter connection database is not connected, always show connection error, but there is no error information, it is difficult to debug.
The solution is: Add this code at the end of the application/config/database.php file:
Copy Code code as follows:
Echo ' <pre> ';
Print_r ($db [' Default ']);
Echo ' </pre> ';
Echo ' Trying to connect to database: '. $db [' Default '] [' database '];
$DBH =mysql_connect
(
$db [' Default '] [' hostname '],
$db [' Default '] [' username '],
$db [' Default '] [' password ']]
Or Die (' cannot connect to the database because: '. mysql_error ());
mysql_select_db ($db [' Default '] [' database ']);
Echo ' <br/> Connected OK: ';
Die (' File: '. __file__. '--> line: '. __line__;
An error is displayed, the problem is mysql_connect (): No such file or directory error.
Because of the previous use of CI did not this error, Google found it because the MySQL is brew installed, because the path problem caused PHP can not get the relevant data.
Solution:
If you already have a/tmp/mysql.sock but no/var/mysql/mysql.sock you should:
Copy Code code as follows:
Cd/var
mkdir MySQL
CD MySQL
Ln-s/tmp/mysql.sock Mysql.sock
If you have/var/mysql/mysql.sock but not Mysql.sock name:
Copy Code code as follows:
Cd/tmp
Ln-s/var/mysql/mysql.sock Mysql.sock