<?php
class DbOperations
{
private $con;
function __construct()
{
require_once dirname(__FILE__).'/DbConnect.php';
$db = new DbConnect();
$this->con = $db->connect();
}
public function createUser($email, $password, $gender, $dob_year, $dob_month, $dob_day, $time_registered)
{
if($this->isUserExist($email))
{
echo "0";
return 0;
}
else
{
$stmt = $this->con->prepare("insert into table_user (`id`, `email`, `password`, `gender`, `dob_year`, `dob_month`, `dob_day`, `time_registered`) values (NULL, ?, ?, ?, ?, ?, ?, ?);");
$stmt->bind_param("sssssss", $email, $password, $gender, $dob_year, $dob_month, $dob_day, $time_registered);
if($stmt->execute())
{
echo "1";
return 1;
}
else
{
echo "2";
return 2;
}
}
}
private function isUserExist($email)
{
$stmt = $this->con->prepare("select id from table_user where email = ?");
$stmt->bind_param("s", $email);
$stmt->execute();
$stmt->store_result();
return $stmt->num_rows > 0;
}
}
?>
嗨,我想做一个注册页面。当我从isUserExists()方法返回true或false时,createUser函数完美工作。看起来像$ stmt-> num_rows> 0;总是返回false,但我看到数据被保存到数据库中。它应该在用户注册时将返回值更改为true,但它总是返回false。这有什么问题?php isUserExist always always
什么'$这个 - > CON组> prepare','$ stmt->的execute()的返回值;'和'$ stmt-> store_result()'?另外,您是否启用了错误报告? (请参阅[如何获取PHP错误以显示](https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display)) – ccKep
都是1和1 – Eric