我只是尝试PDO,我得到这个错误,致命错误:调用一个非对象的成员函数fetch(),但不是它已经在$ this-> db对象上?PDO:调用一个非对象的成员函数fetch()?
class shoutbox {
private $db;
function __construct($dbname, $username, $password, $host = "localhost")
{ # db conections
try {
$this->db = new PDO("mysql:host=".$hostname.";dbname=".$dbname, $username, $password);
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
function getShouts()
{
$sql_shouts = $this->db->query('SELECT shoutid, message, pmuserid, ipadress, time FROM shouts WHERE pmuserid == 0');
return $sql_shouts->fetch(PDO::FETCH_OBJ);
}
}
如果您使用的Microsoft SQL Server保留字的方式[时间]被使用。 – Crypth 2011-10-22 11:10:27