In php, if we want to connect to a remote database, the method is also very simple. we just need to change the local connection localhost or 127.0.0.1 to a specified remote server IP address. syntax: mysql_connect (servernam... in php, if we want to connect to a remote database, the method is also very simple. we just need to change the local connection localhost or 127.0.0.1 to a specified remote server IP address.
Syntax: mysql_connect (servername, username, password );
Example: In the following example, we store the connection in a variable ($ con) in the script for later use. if the connection fails, the "die" part will be executed, the code is as follows:
The above is to connect to the local database. now you can change localhost to a remote IP address. the instance code is as follows:
$ Conn = mysql_connect ('192. 125.221.25 ', 'root', '123'); if (! $ Conn) echo "failed! "; Else echo" successful! "; // Open-source code phprm.com // SQL statement for extracting information FROM the table $ SQL =" SELECT * FROM user where userName = '$ user_name '"; // execute SQL query $ result = mysql_db_query ('info', $ SQL, $ conn); // Obtain the query result $ row = mysql_fetch_row ($ result); mysql_close ();
Tutorial URL:
You are welcome to add your _ favorites to the Favorites folder, but please keep the link for this article.