php5的程序升级到php7后数据库不可用,修改代码替换mysqli函数的方法,简易升级步骤
php5升级前mysql_connect ($ip, $dbuser, $dbpass)or die("无法连接到数据库: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());
$md5pass = md5($pass);
$checkuser = mysql_query("SELECT * FROM user WHERE name='$user' and password='$md5pass'");
@$username_exist = mysql_num_rows($checkuser);
if($username_exist >= 1)
php7修改后
$link = mysqli_connect ($ip, $dbuser, $dbpass, $dbname);
if (mysqli_connect_errno($link))
{
echo "无法连接到数据库: " . mysqli_connect_error();
}
$md5pass = md5($pass);
$checkuser = mysqli_query($link,"SELECT * FROM user WHERE name='$user' and password='$md5pass'");
@$username_exist = mysqli_fetch_row($checkuser);
if($username_exist >= 1)
else之类语句完毕用完后记得随手关闭数据库
mysqli_close($link);
{:3069:}
页:
[1]