我正在将一些旧的 PHP 代码从 mysql 移植到 MySQLi,但我遇到了一个小问题.
I'm porting some old PHP code from mysql to MySQLi, and I've ran into a minor snag.
有没有相当于旧的mysql_result()函数?
Is there no equivalent to the old mysql_result() function?
我知道 mysql_result() 在处理多于 1 行时比其他函数慢,但很多时候我只有 1 个结果和 1 个字段.使用它可以让我将 4 行压缩成 1 行.
I know mysql_result() is slower than the other functions when you're working with more than 1 row, but a lot of the time I have only 1 result and 1 field. Using it lets me condense 4 lines into 1.
旧代码:
if ($r && mysql_num_rows($r))
$blarg = mysql_result($r, 0, 'blah');
所需代码:
if ($r && $r->num_rows)
$blarg = $r->result(0, 'blah');
但是没有这样的事情.:(
But there is no such thing. :(
有什么我遗漏的吗?或者我将不得不把它搞砸并制作一切:
Is there something I'm missing? Or am I going to have to suck it up and make everything:
if ($r && $r->num_rows)
{
$row = $r->fetch_assoc();
$blarg = $row['blah'];
}
PHP 5.4 现在支持 函数数组解引用,这意味着您可以这样做:
PHP 5.4 now supports function array dereferencing, which means you can do this:
if ($r && $r->num_rows)
{
$row = $r->fetch_assoc()['blah'];
}
这篇关于MySQLi 相当于 mysql_result()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
mysql 中的 store_result() 和 get_result() 返回 falsestore_result() and get_result() in mysql returns false(mysql 中的 store_result() 和 get_result() 返回 false)
调用未定义的函数 mysqli_result::num_rows()Call to undefined function mysqli_result::num_rows()(调用未定义的函数 mysqli_result::num_rows())
PHP 准备好的语句问题PHP Prepared Statement Problems(PHP 准备好的语句问题)
mysqli_fetch_array 只返回一个结果mysqli_fetch_array returning only one result(mysqli_fetch_array 只返回一个结果)
PHP MySQLi 多次插入PHP MySQLi Multiple Inserts(PHP MySQLi 多次插入)
如何确保 MySQL 中的值在 PHP 中保持其类型?How do I make sure that values from MySQL keep their type in PHP?(如何确保 MySQL 中的值在 PHP 中保持其类型?)