嗨iam使用php 7,並被告知它不支持Mysql函數。我研究了網絡,發現fix_mysql.inc.php被告知將所有Myaql函數替換爲Mysqli,但現在我不知道如何實現它。請幫忙!如何使用fix_mysql.inc.php文件替換Mysqli的所有MySql函數
fix_mysql.inc.php
<?php
/**
* replacement for all mysql functions
*/
if (!function_exists("mysql_connect")){
/* warning: fatal error "cannot redeclare" if a function was disabled in php.ini with disable_functions:
disable_functions =mysql_connect,mysql_pconnect,mysql_select_db,mysql_ping,mysql_query,mysql_fetch_assoc,mysql_num_rows,mysql_fetch_array,mysql_error,mysql_insert_id,mysql_close,mysql_real_escape_string,mysql_data_seek,mysql_result
*/
function mysql_connect($host, $username, $password){
global $dbconnect;
$dbconnect = mysqli_connect($host, $username, $password);
return $dbconnect;
}
function mysql_pconnect($host, $username, $password){
global $dbconnect;
$dbconnect = mysqli_connect("p:".$host, $username, $password);
return $dbconnect;
}
function mysql_select_db($db,$dbconnect){
return mysqli_select_db ($dbconnect,$db);
}
function mysql_ping($dbconnect){
return mysqli_ping ($dbconnect);
}
function mysql_query($stmt){
global $dbconnect;
return mysqli_query ($dbconnect, $stmt);
}
function mysql_fetch_assoc($erg){
return mysqli_fetch_assoc ($erg);
}
function mysql_num_rows($e){
return mysqli_num_rows ($e);
}
function mysql_affected_rows($e=NULL){
return mysqli_affected_rows ($e);
}
function mysql_fetch_array($e){
return mysqli_fetch_array ($e);
}
function mysql_error(){
global $dbconnect;
return mysqli_error ($dbconnect);
}
function mysql_insert_id($cnx){
return mysqli_insert_id ($cnx);
}
function mysql_close(){
return true;
}
function mysql_real_escape_string($s){
global $dbconnect;
return mysqli_real_escape_string($dbconnect,$s);
}
function mysql_data_seek($re,$row){
return mysqli_data_seek($re,$row);
}
function mysql_result($res,$row=0,$col=0){
$numrows = mysqli_num_rows($res);
if ($numrows && $row <= ($numrows-1) && $row >=0){
mysqli_data_seek($res,$row);
$resrow = (is_numeric($col)) ? mysqli_fetch_row($res) : mysqli_fetch_assoc($res);
if (isset($resrow[$col])){
return $resrow[$col];
}
}
return false;
}
function mysql_get_server_info() {
global $dbconnect;
return mysqli_get_server_info($dbconnect);
}
function mysql_set_charset($csname) {
global $dbconnect;
return mysqli_set_charset($dbconnect,$csname);
}
function mysql_fetch_object($result) {
return mysqli_fetch_object($result);
}
}
如果」重新開始一個新項目,不要使用這個。請使用[** PDO **](https://secure.php.net/manual/en/book.pdo.php)函數與[** prepared statements **](https://secure.php.net) /manual/en/pdo.prepare.php)和[** bound parameters **](https://secure.php.net/manual/en/pdostatement.bindparam.php)。 –
我已經開始項目,幾乎完成了它。 –
如果你使用這個,你將很容易受到[** SQL注入**](https://en.wikipedia.org/wiki/SQL_injection)攻擊。 –