【发布时间】:2015-05-12 14:31:20
【问题描述】:
我正在将一些 PHP 代码从 mysql 转换为 mysqli。我创建了一个错误,无法理解如何修复它。任何建议将不胜感激。
代码如下所示:
<?php
include ("admin/includes/connect.php");
$query = "select * from posts order by 1 DESC LIMIT 0,5";
$run = mysqli_query($conn["___mysqli_ston"], $query);
while ($row=mysqli_fetch_array($run)){
$post_id = $row['post_id'];
$title = $row['post_title'];
$image = $row['post_image'];
?>
产生的错误是:致命错误:不能使用mysqli类型的对象作为数组 该行正在调用错误:
$run = mysqli_query($conn["___mysqli_ston"], $query);
在上面的行中,$conn 是数据库连接文件中的一个变量,它具有以下代码:
<?php
// Stored the db login credentials in separate file.
require("db_info.php");
// Supressing automated warnings which could give out clues to database user name, etc.
mysqli_report(MYSQLI_REPORT_STRICT);
// Try to open a connection to a MySQL server and catch any failure with a controlled error message.
try {
$conn=mysqli_connect ('localhost', $username, $password) or die ("$dberror1");
} catch (Exception $e ) {
echo "$dberror1";
//echo "message: " . $e->message; // Not used for live production site.
exit;
}
// Try to Set the active MySQL databaseand catch any failure with a controlled error message.
try {
$db_selected = mysqli_select_db($conn, $database) or die ("$dberror2");
} catch (Exception $e ) {
echo "$dberror2";
//echo "message: " . $e->message; // Not used for live production site.
exit;
// We want to stop supressing automated warnings after the database connection is completed.
mysqli_report(MYSQLI_REPORT_OFF);
}
?>
【问题讨论】:
标签: php arrays mysqli compiler-errors