PHP5 recommend using PDO or mysqli to connect to the database later
<?PHP$servername= "127.0.0.1";$username= "Root";$password= "Root";Try { $pdo=NewPDO ("mysql:host=$servername;d Bname=mydb ",$username,$password); Echo"Connection succeeded"; }Catch(pdoexception$e){ Echo $e-getMessage ();}//$list = $pdo, query ("Set names UTF8");$list=$pdoQuery ("SELECT * from MyTable"); while($row=$list-Fetch ()) { Print_r($row); }
<?PHP$servername= "127.0.0.1";$username= "Root";$password= "Root"; //Create a connection$mysqli=NewMysqli ($servername,$username,$password); //Detecting Connectionsif($mysqli-connect_error) { die("Connection failed:".)$mysqli-connect_error);} $mysqli->select_db (' three ');//$mysqli->query (' Set names UTF8 ');$list=$mysqli->query (' select * from Jing_province '); while($row=$list-Fetch_row ()) { Print_r($row);}
PHP connection MySQL