First CodeIgniter connection database is not connected, always show connection error, but there is no error information, difficult to debug.
The solution is: Add this piece of code at the end of the application/config/database.php file:
Copy the Code code as follows:
Echo '
';
Print_r ($db [' Default ']);
Echo '
';
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 '
Connected OK: ';
Die (' File: '. __file__. '--line: '. __line__);
Display error, the problem is mysql_connect (): No such file or directory error.
Because it used to be a CI without this error, Google discovered that because MySQL is a brew installation, because the path problem causes PHP to not get the relevant data.
Solution:
If you already have a/tmp/mysql.sock but no/var/mysql/mysql.sock you should:
Copy the Code code as follows:
Cd/var
mkdir MySQL
CD MySQL
Ln-s/tmp/mysql.sock Mysql.sock
If you have a/var/mysql/mysql.sock but no mysql.sock name:
Copy the Code code as follows:
Cd/tmp
Ln-s/var/mysql/mysql.sock Mysql.sock