Home >Backend Development >PHP Tutorial >CodeIgniter error mysql_connect(): No such file or directory solution, nosuchfile_PHP tutorial
First of all, CodeIgniter cannot connect to the database. It always displays a connection error, but there is no error message, making it difficult to debug.
The solution is: add this code at the end of the application/config/database.php file:
';<br> print_r($db['default']);<br> 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__);
An error is displayed. The problem is mysql_connect(): No such file or directory error.
Because I have used CI before and did not have this error, I googled and found that it was because MySQL was installed with brew, and PHP was unable to obtain relevant data due to path problems.
Solution:
If you already have /tmp/mysql.sock but not /var/mysql/mysql.sock you should:
If you have /var/mysql/mysql.sock but not mysql.sock name:
Is the file accessed in the program? There is a big possibility that the program uses a relative path when accessing the file, that is, the path to execute the program. When the program is executed, the root path is not what you expect, so access it There is no real document left.
Another possibility is that the root path of the program execution in the debugging state (are you using VC) is different from the root path of the program execution in the release state.
It is not possible to directly copy a graphics.h under VC, you must have the corresponding .lib. The original poster looks here: code.google.com/p/vcgraphics/downloads/list
Download the VCGraph(V20091123).zip and install it into your VC6. There are instructions inside. Or, there is VC6.7z in it, which has graphics.h configured, and you can use it directly after downloading.