Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
mysql到mysqli php,只需输入“i”?_Php_Mysql_Mysqli - Fatal编程技术网

mysql到mysqli php,只需输入“i”?

mysql到mysqli php,只需输入“i”?,php,mysql,mysqli,Php,Mysql,Mysqli,我有一个网站,是在线约5年。刚才我注意到我使用的是mysql连接 我想把它改成mysqli 所以,我有一些问题。 要将mysql改为mysqli,我只需要在所有mysql单词后面加上I 质疑 行数: $num = mysql_num_rows($rs); to $num = mysqli_num_rows($rs); 字符串转义: mysql_real_escape_string to mysqli_real_escape_string 提拉 $l = mysql_fetch_array(

我有一个网站,是在线约5年。刚才我注意到我使用的是mysql连接

我想把它改成mysqli

所以,我有一些问题。 要将mysql改为mysqli,我只需要在所有mysql单词后面加上I

质疑

行数:

$num = mysql_num_rows($rs);
to
$num = mysqli_num_rows($rs);
字符串转义:

mysql_real_escape_string
to
mysqli_real_escape_string
提拉

 $l = mysql_fetch_array($re);
to
 $l = mysqli_fetch_array($re);

这简单吗?或者我需要知道一些其他的东西?

不,这不是那么简单..mysqli函数通常需要第二个参数…所以请检查您正在更改的任何函数的语法。
例如..用my_用户、my_密码代替mysql_connectlocalhost;对于mysqli,您将使用mysqli\u connectlocalhost、我的用户、我的密码、我的数据库

这实际上会引导您完成:

虽然mysql只是过程样式的函数,但新的mysqli同时是:过程样式和对象样式

您可以使用面向对象的样式,如:

$mysqli = new mysqli('localhost', 'my_user', 'my_password', 'my_db');
if ($mysqli->connect_error) {
die('Connect Error (' . $mysqli->connect_errno . ') '
        . $mysqli->connect_error);
}
或程序风格:

$link = mysqli_connect('localhost', 'my_user', 'my_password', 'my_db');

if (!$link) {
  die('Connect Error (' . mysqli_connect_errno() . ') '
        . mysqli_connect_error());
}

mysqli的参数是反向的,即mysql_query$q,$dbc变成mysqli_query$dbc,$q。还有一些函数需要额外的参数,通常是连接。Php.net有所有更改的完整列表

更新:

//your connection script should look somthing like this.
$db_connnect = mysqli_connect('localhost','username','password','db_name');

//the page you require the connection on should look something like this.
require_once ('db_connect.php');

//a mysqli query would look something like this.
$q = "select * from user limit 12";
$r = mysqli_query("$db_connnect, $q"); 

while($row = mysqli_fetch_array($r)) { ... }

请看一下mysqli函数的php手册,我使用的是这样的:$users=mysql\u queryselect*from user limit 12;虽然$usersfetch=mysql\u fetch\u array$users{…},但我的mysql\u查询没有任何数据库名称,可以正常工作。mysqli不会工作吗?
//your connection script should look somthing like this.
$db_connnect = mysqli_connect('localhost','username','password','db_name');

//the page you require the connection on should look something like this.
require_once ('db_connect.php');

//a mysqli query would look something like this.
$q = "select * from user limit 12";
$r = mysqli_query("$db_connnect, $q"); 

while($row = mysqli_fetch_array($r)) { ... }