问题描述
由于有了答案,我发现我无法使用fetch_all()
,因为我在PHP 5.2.17
-fetch_assoc
中使用了while
循环.
Thanks to the answers I have figured out that I am unable to use fetch_all()
because i am using PHP 5.2.17
- fetch_assoc
with while
loop worked.
我正在使用的功能fetch_all
再次出现此错误:
The function I am using fetch_all
is coming back with this error:
$mysqli = new mysqli($host, $username, $password, $database);
$query = "LONG QUERY that works, tested in phpmyadmin"
$result = $mysqli->query($query);
$result->fetch_all(); or $mysqli->fetch_all() tried both
mysqli_fetch_all() was already tried.
$mysqli->close();
我能够连接到数据库,并且已经拉出了单行.当我将查询放入PHPMYADMIN时,我会返回5行.
I am able to connect to the DB and I have pulled single rows. When I place the query in PHPMYADMIN I get 5 rows back.
此功能是否还有效?有没有办法我可以将数据自己放置到一个assoc数组中?
Does this function even work? Is there a way I can place my data into an assoc array on my own?
推荐答案
此功能自PHP 5.3.0起可用.可能是您的版本较旧.改为使用fetch_assoc()
.
This function is available since PHP 5.3.0. Possibly your version is older. Use fetch_assoc()
instead.
while ($row = $result->fetch_assoc()) {
// do what you need.
}
这篇关于mysqli fetch_all()不是有效函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!