<?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