Mysqli引发尝试获取非对象错误的属性 [英] Mysqli throws trying to get property of non-object error

查看:67
本文介绍了Mysqli引发尝试获取非对象错误的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个脚本,可以用来从一个表中选择一个描述并将其插入到另一个表中.

I have this script which i am using to select a description from one table and inserting it into another table.

<?php
/**
Report Errors
*/
error_reporting(E_ALL);

$mysqli = new mysqli("localhost", "root", "", "test");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$result = $mysqli->query("select subscriber_number,subscriber_category from subscriber_choices");

/*
500 Records Here
*/

$i = 0;
while($row = $result->fetch_array())
{
$subscriber_number = $row['subscriber_number'];
$subscriber_category = $row['subscriber_category'];

$mysqli->query("select description from jobs_content where category = $subscriber_category order by rand() limit 1 ");

$text_message = $mysqli->query("select description from jobs_content where category = '$subscriber_category' order by rand() limit 1")->fetch_object()->description; 

$mysqli->query("insert into le_grand_out dest_msisdn,text_message,sender_name,service_id values ($subscriber_number,'$text_message',6789900,6388398399004)");

}

$result->close()

?>

当我运行此脚本时,在此行出现错误

When i run this script,i get an error on this line

$text_message = $mysqli->query("select description from jobs_content where category = '$subscriber_category' order by rand() limit 1")->fetch_object()->description; 

例如当我写时有效

$text_message = $mysqli->query("select description from jobs_content where category = 'general' order by rand() limit 1")->fetch_object()->description; 

我为什么会收到此错误

Notice: Trying to get property of non-object in /var/www/html/send_sms.php on line 26 

推荐答案

因此,如果您的查询没有结果,那么您正在运行:

So, if your query has no results your are running:

null->description

这是非对象的属性.

这篇关于Mysqli引发尝试获取非对象错误的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆