Php cannot connect to the database mysql

Source: Internet
Author: User
On the local windows system, I set up the apache, php, and mysql environments. Use the following code: $ linkmysql_connect (& #39; localhost & #39;, & #39; Username & #39;, & #39; password & #39 ;); if (! $ Link) echo & quot; failed! & Quot; elseecho & quot; success! & Quot; mysql_close (); failed is displayed on the page. Help ~ After an afternoon, please advise. Troubleshooting: successful connections to navicat php databases

On the local windows system, I set up the apache, php, and mysql environments.

Use the following code:
$ Link = mysql_connect ('localhost', 'username', 'password ');
If (! $ Link)
Echo "failed! ";
Else
Echo "success! ";
Mysql_close ();
The page displays failed.

Help ~ After an afternoon, please advise.

Troubleshooting:
If navicat can successfully connect to the database, the port number is 3306, and the account and password are correct.
Safemode = off (security mode not enabled) in php. ini)
C: \ WINNT \ system32 \ drivers \ etc \ hosts added 127.0.0.1 localhost
Phpinfo () is displayed as follows:

Mysql

MySQL Support enabled
Active Persistent Links 0
Active Links 0
Client API version mysqlnd 5.0.11-dev-20120503-$ Id: bf9ad53b11c9a57efdb1057292d73b928b8c5c77 $

Directive Local Value Master Value
Mysql. allow_local_infile On
Mysql. allow_persistent On
Mysql. connect_timeout 60 60
Mysql. default_host no value
Mysql. default_password no value
Mysql. default_port no value
Mysql. default_socket no value
Mysql. default_user no value
Mysql. max_links Unlimited
Mysql. max_persistent Unlimited
Mysql. trace_mode Off

Thank you ~

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.