我的代码适用于php 5.6但不适用于php 7.0。它很短,所以我想我能够毫无问题地修改它,但我错了。原始脚本如下,然后我尝试使用mysqli。请某位善意的人请告诉我我需要做些什么才能做到正确?
旧代码
<?php
$db_host = "localhost";
$db_name = "database_name";
$db_user = "user_name";
$db_pass = "pass";
$link = mysql_connect($db_host, $db_user, $db_pass) or die("Could not connect to database as ".$db_user."@".$db_host."!");
mysql_select_db($db_name) or die("Could not select database ".$db_name);
?>
新代码
<?php
$db_host = "localhost";
$db_name = "database_name";
$db_user = "user_name";
$db_pass = "pass";
$link = new mysqli_connect($db_host,$db_user,$db_pass) or die('Unable to establish a DB connection');
mysqli_select_db($db_name) or die("Could not select database ".$db_name);
?>