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:
Echo ' <pre> ';p rint_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: ' ;d ie (' 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:
Cd/var mkdir mysqlcd mysqlln-s/tmp/mysql.sock mysql.sock
If you have a/var/mysql/mysql.sock but no mysql.sock name:
Cd/tmpln-s/var/mysql/mysql.sock Mysql.sock
Original answer address: http://stackoverflow.com/questions/12584762/mysql-connect-no-such-file-or-directory
[PHP] CodeIgniter Database error and mysql_connect (): No such file or directory error