2015-11-19 75 views
0

嗨im试图从mysql更改为mysqli和ive使用了一个编辑器,它将所有更改并即时通讯更改所有文件后出现以下错误 致命错误:调用成员函数query()非对象/home/matureco/public_html/config/db_connect.php第7行从mysql更改为mysqli后出现错误

继承人的一块编码为

$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

+1

'mysqli(DBHOST,DBUSER,DBPASS)'这里缺少什么?我会让你考虑一下。编辑:哦和错误的变量。 http://php.net/manual/en/function.mysqli-connect.php --- http://php.net/manual/en/mysqli.error.php –

回答

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

我认为你看到了我的评论;-) 'mysqli_connect(“my_host”,“my_user”,“my_password”,“my_db”);'最初并不在那里嘿 –

+0

我把那行放入,现在我得到以下警告:mysqli_fetch_array()期望参数1是mysqli_result,布尔在第7行给出的/home/matureco/public_html/config/db_connect.php –

+0

继承人db连接文件的详细信息hun <?php define(“DBHOST”,“localhost”); define(“DBUSER”,“matureco_social”); define(“DBPASS”,“password”); define(“DBNAME”,“matureco_social”); /* define(“DBUSER”,“root”); define(“DBPASS”,“”); define(“DBNAME”,“date_demo”); */ define(“DBPREFIX”,“”); define(“CHAR_SET”,“utf8”); define(“CACHEDIR”,“”); ?> –

0

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

$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); 
+0

我试过了上面的Burak代码,但我只是得到了更多的错误 –

+0

,因为我忘了改变事情,我告诉你现在我编辑它:)我希望它的作品控制你的变量语法电子邮件,标志,关键字我可能犯了错误而写他们。我怀疑修剪和stripslashed方法,如果你得到错误,你最好检查这些。 –

+0

ive解决了这一行现在我得到了第67行致命错误的一个错误:调用一个成员函数的查询()在/ home/!'$ ID“。readflage和= 0和状态function_exists(unReadMsgCount)) { \t功能unReadMsgCount($ ID) \t { \t \t返回$ conn->查询( ”从消息,其中rece_id =选择*“' = 1" ) - > NUM_ROWS; \t} }'code' –