Mysql can be connected to a command line, but php cannot.

Source: Internet
Author: User
Mysql can be connected to the command line. php cannot be used on the web host. mysql & nbsp;-h & nbsp; 192.168.7.14 & nbsp;-uroot & nbsp;-proot & nbsp; -D & nbsp; sheep & nbsp; you can connect to a remote database and view the data in it. However, the connection to the mysql command line failed when I used php on the same server.
On the web host, I can use mysql-h 192.168.7.14-uroot-proot-D sheep to connect to the remote database and view the data in it.
However, the connection to the same server using php fails.

define('DB_HOST', '192.168.7.14:3306');
define('DB_USER', 'root');
define('DB_PASSWORD', 'root');
define('DB_NAME', 'sheep');

$conn=mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) or die("wrong while connect DB!");
mysql_select_db(DB_NAME,$conn) or die("wrong while select DB!");
mysql_query("set names utf8");
echo "test";
mysql_close($conn);
?>

Output "wrong while connect DB!" directly !", The port cannot be removed, and the constant cannot be directly written in the mysql_connect parameter. I shut down the firewall, and the web Directory contains the root owner and group.
What's the possibility? Share:
------ Solution --------------------
You set die ("wrong while connect DB! ") Changed
Die (mysql_error ())
------ Solution --------------------
You do not need to specify Port 3306.
------ Solution --------------------
If you have paid for the program and the server, use localhost directly.
------ Solution --------------------
Echo phpinfo (); check whether mysql expansion works.

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.