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

Source: Internet
Author: User
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

  • 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.