我似乎无法弄清楚我的数据库或连接到它的问题。当我试图运行它时,我得到了这个错误。
注意:试图获得非对象的属性在/Applications/XAMPP/xamppfiles/htdocs/swiftappandmysql/db/mysqlda.php行54
和
致命错误:未捕获异常' exception '在/Applications/XAMPP/xamppfiles/htdocs/swiftappandmysql/db/MySQLDAO.php:53堆栈跟踪:#0/Applications/XAMPP/xamppfiles/htdocs/swiftappandmysql/scripts/registerUser.php(41): MySQLDAO->registerUser('email', 'aske', 'meyer', '1bf528e7f15d11c…', 'KO'x8E'xD0'xCE/'xBD'xACK'xD1d'x18'x9A'x07'xE1…')#1 {main}抛出在/Applications/XAMPP/xamppfiles/htdocs/swiftappandmysql/db/mysqlda1 .php第53行
连接文件:
<?php class Conn { public static $dbhost = "localhost";
public static $dbuser = "root";
public static $dbpass = "";
public static $dbname = "app";} ?>
MySQL文件
public function registerUser($email, $first_name, $last_name, $password, $salt)
{
$sql = "insert into users set email=?, first_name=?, last_name=?, user_password=?, salt=?";
$statement = $this->conn->prepare($sql);
if (!$statement)
throw new Exception($statement->error);
$statement->bind_param("sssss", $email, $first_name, $last_name, $password, $salt);
$returnValue = $statement->execute();
return $returnValue;
}
第54行。if (!$statement) throw new Exception($statement->error);
if()
块在$statement = FALSE
时运行,因此$statement->error
不可能正确。error
属性在$this->conn
中,所以它应该是
if (!$statement) {
throw new Exception($this->conn->error);
}
错误信息将显示SQL的问题