CodeIgniter error mysql_connect (): No such file or directory solution _php instance

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.