[PHP] CodeIgniter Database error and mysql_connect (): No such file or directory error

Source: Internet
Author: User
Tags codeigniter

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

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.