[英]using mysqli to fetch data
我一直在尝试mysqli。
使用过程mysql,代码可以很好地显示结果。 但是,在切换到OOP mysqli之后,我尝试将代码转换为mysqli,它说没有引号。 代码有什么问题吗?
/* 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;
}
}
您没有将变量绑定到结果集列
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.