Php 使用mysqli获取数据
我一直在尝试我的mysqli 使用过程mysql,代码可以很好地显示结果。但是,在切换到OOP mysqli之后,我尝试将代码转换为mysqli,它说没有引号。 代码有什么问题吗Php 使用mysqli获取数据,php,mysql,oop,mysqli,Php,Mysql,Oop,Mysqli,我一直在尝试我的mysqli 使用过程mysql,代码可以很好地显示结果。但是,在切换到OOP mysqli之后,我尝试将代码转换为mysqli,它说没有引号。 代码有什么问题吗 /* the database object */ private $_db; public function __construct($db=NULL) { if(is_object($db)) {
/* the database object */
private $_db;
public function __construct($db=NULL)
{
if(is_object($db))
{
$this->_db = $db;
}
else
{
$this->_db = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
}
}
public function displayQuotes()
{
$sql = "SELECT cQuotes, vAuthor, cArabic, vReference
FROM thquotes
ORDER BY RAND()
LIMIT 1;";
try {
$query = $this->_db->prepare($sql);
$query->execute();
$query->store_result();
/* bind variables to prepared statement */
$query->bind_result($cQuotes, $vAuthor, $cArabic, $vReference);
if(!$query->num_rows==0)
{
while($row = $query->fetch())
{
//echo $this->formatQuotes($row);
$formatHTML = new formatHTML();
echo $formatHTML->formatQuotes($row);
}
}
else
{
echo "There are no Quotes!";
}
$query->free_result();
$query->close();
}
catch (Exception $ex){
echo "Something went wrong " . $ex;
}
}
您没有将变量绑定到resultset列
我在检查记录数是否为0之前尝试了绑定,如下所示:
$stmt->bind\u result($col1,$col2,$col3,col4)代码>并且仍然显示“无引号”。这是正确的方法吗?或者我遗漏了什么?将if(!$query->num_rows()==0)
更改为if(!$query->num_rows==0)
这是一个属性,而不是一个方法。我这样做了。还是不行。我已经用更改更新了代码。请检查。啊。。。您需要先存储结果,然后才能计算行数:我运行了调试器,它将$query显示为null。为什么它不读取数据?