-1
我有代碼可以使用PHP5.6,但不能使用PHP7.0。這很短,所以我認爲我可以在沒有問題的情況下進行修改,但我錯了。原始腳本在下面,接着我嘗試使用mysqli。有人請告訴我我需要做些什麼才能做到正確嗎?適應php代碼使用mysqli而不是mysql
OLD CODE
<?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);
?>
您好,歡迎計算器。我不認爲這是一個問題,因爲你可以通過以下步驟自己回答:1.打開http://google.com - 2:尋找「php mysqli connect」 - 3:享受234589734示例,只是像他們做的那樣:) – Twinfriends
這是stackoverflow的問題:)謝謝你! – MorganFreeFarm