如何將mysql改為mysqli
<p>基於下面的程式碼,我用於常規的mysql,我應該如何將其轉換為使用mysqli? </p><p>只要將mysql_query($sql);改為mysqli_query($sql);,是這樣簡單嗎? </p><p><strong><code></code><code></code></strong></p>
<pre class="brush:php;toolbar:false;"><?PHP
//in my header file that is included on every page I have this
$DB["dbName"] = "emails";
$DB["host"] = "localhost";
$DB["user"] = "root";
$DB["pass"] = "";
$link = mysql_connect($DB['host'], $DB['user'], $DB['pass']) or die("<center>An Internal Error has Occured. Please report following error to the webmaster .<br><br>".mysql_error()."'</center>");
mysql_select_db($DB['dbName']);
// end header connection part
// function from a functions file that I run a mysql query through in any page.
function executeQuery($sql) {
$result = mysql_query($sql);
if (mysql_error()) {
$error = '<BR><center><font size=" 1" face="arial" color="red">An Internal Error has Occured.<BR> The error has been recorded for review< /font></center><br>';
if ($_SESSION['auto_id'] == 1) {
$sql_formatted = highlight_string(stripslashes($sql), true);
$error .= '<b>The MySQL Syntax Used</b><br>' . $sql_formatted . '<br><br><b>The My MySQL Error Returned<<br><b>The My MySQL Error Returned<<br><b>The MySQL Error Returned</b>lt;/b> ;' . mysql_error();
}
die($error);
}
return $result;
}
// example query ran on anypage of the site using executeQuery function
$sql='SELECT auto_id FROM friend_reg_user WHERE auto_id=' .$info['auto_id'];
$result_member=executequery($sql);
if($line_member=mysql_fetch_array($result_member)){
extract($line_member);
} else {
header("location: index.php");
exit;
}
?></pre>
<p><br /></p>