Code sharing that tests whether php connects to mysql successfully
- 2020-12-21 18:00:14
- OfStack
The method is simple:
Save the following code as test.php and put it in the web directory to execute it.
<?php
/**
* test php with mysql The connection
* Editor: www.ofstack.com
*/
$link=mysql_connect("localhost","root","123");
if(!$link) echo "FAILD! Wrong connection, wrong username and password ";
else echo "OK! Can be connected ";
?>
The parameters of the mysql_connect() function are, in turn, mysql server name or IP, mysql user name and mysql user password.