我正在尝试使用一些记住我的课程,现在问题是我得到了
Call to a member function prepare() on a non-object
而且我没有收到任何错误:
索引.php:
try {
$connection = new PDO('mysql:host=localhost;dbname=ibids', 'root', '');
}
catch (PDOException $e)
{
printf ($e);
}
$storage = new Rememberme_Storage_PDO($connection);
$rememberMe = new Rememberme($storage);
我将连接发送到此文件: pdo.php 并在那里使用此代码:
class Rememberme_Storage_PDO extends Rememberme_Storage_DB {
/**
*
* @var PDO
*/
protected $connection;
public function getConnection() {
return $this->connection;
}
public function setConnection(PDO $connection) {
try {
$this->connection = $connection;
}
catch (PDOException $e)
{
printf ($e);
}
}
}
我在这个函数上有错误:
** Rememberme_Storage_PDO 类中的这个函数
public function storeTriplet($credential, $token, $persistentToken, $expire=0) {
$sql = "INSERT INTO {$this->tableName}({$this->credentialColumn}, " .
"{$this->tokenColumn}, {$this->persistentTokenColumn}, " .
"{$this->expiresColumn}) VALUES(?, SHA1(?), SHA1(?), ?)";
$query = $this->connection->prepare($sql);
if(!$query->execute(array($credential, $token, $persistentToken, date("Y-m-d H:i:s", $expire))))
{
die('excute faild');
}
}
说:
Fatal error: Call to a member function prepare() on a non-object in F:\wamp\www\rememberme-master\src\Rememberme\Storage\PDO.php on line 44
我是 PDO 的新手,我做错了什么?