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.