在使用MySQL一段时间之后,我才开始尝试使用MySQLi。 我在教程中找到了这个小代码片段,并且对它有一个疑问(因为Google不会在此返回任何结果......)。 p>
&lt ;?php
$ link = mysqli_connect(“127.0.0.1”,“user”,“password”,“world”);
if(!$ link)
{
$ error = mysqli_connect_error();
$ errno = mysqli_connect_errno();
print“$ errno:$ error
”;
exit(); \ n}
$ query =“SELECT Name,Population,Continent FROM Country WHERE Continent =?ORDER BY Name LIMIT 1”;
$ stmt = mysqli_stmt_init($ link);
if(!mysqli_stmt_prepare($ stmt) ,$ query))
{
print“无法准备语句
”;
}
else
{
\ mysqli_stmt_bind_param($ stmt,“s”,$ continent);
$ continent_array = 数组('欧洲','非洲','亚洲','北美');
foreach($ continent_array as $ continent)
{
mysqli_stmt_execute($ stmt);
$ result = mysqli_stmt_get_result( $ stmt);
while($ row = mysqli_fetch_array($ result,MYSQLI_NUM))
{
foreach($ row as $ r)
{
print“$ r”;
}
print“
“;
}
}
}
mysqli_stmt_close($ stmt);
mysqli_close($ link);
?>
code> pre>
礼貌 of http://www.php.net/manual/en/mysqli-stmt.get-result.php p>
< 如果我正确理解了这一点,那么 $ r code>现在会在所有被调用的行中找到所有结果的数组。 如何为每一行分配变量? 我还可以像在MySQL中那样做类似的事情吗? p>
$ username = $ row ['username'];
code> pre>
\ n 或者现在有什么完全不同的东西吗? p>
div>