从mysql更改为mysqli后出现错误

时间:2015-11-19 18:45:38

标签: php mysqli

您好我试图从mysql更改为mysqli并且我使用了一个更改所有内容的编辑器并在更改所有文件后收到以下错误 致命错误:在第7行的/home/matureco/public_html/config/db_connect.php中调用非对象的成员函数query()

这是

的编码
    $conn       = new mysqli(DBHOST,DBUSER,DBPASS) or die($mysqli->error);

$row        = mysqli_fetch_array($mysqli->query("select * from settings where id = '1' "));
$site_name  = trim(stripslashes($row['site_name']));
$email      = trim($row['email']);
$keyword    = trim(stripslashes($row['keyword']));
$description= trim(stripslashes($row['description']));
$logo       = trim($row['logo']);
$copyright  = trim(stripslashes($row['copyright']));

$favicon    = trim($row['favicon']);
$paypal_email   = trim($row['paypal_email']);

任何人都可以告诉我我错过了什么

非常感谢ty jan x

2 个答案:

答案 0 :(得分:1)

$mysqli不是代码中的对象。 $conn是您声明的对象。

您的代码应该显示:

$row        = mysqli_fetch_array($conn->query("select * from settings where id = '1' "));

此外,您在对象声明中缺少一个参数来设置数据库本身:

更正语法:

$obj = new mysqli("my_host", "my_user", "my_password", "my_db");

答案 1 :(得分:0)

$mysqli->query("select * from settings where id = '1' "));应该是

$conn->query("select * from settings where id = '1' "));

因为你打算使用oop方法。您应该将代码更改为该方式。 这是我的建议

$result       = $conn->query("select * from settings where id = '1' ");
$row = $result->fetch_object()
$site_name  = trim(stripslashes($row->site_name));
$email      = trim($row->email);
$keyword    = trim(stripslashes($row->keyword));
$description= trim(stripslashes($row->description));
$logo       = trim($row->logo);
$copyright  = trim(stripslashes($row->copyright));

$favicon    = trim($row->favicon);
$paypal_email   = trim($row->paypal_email);