我有一個有趣的問題。num_rows不工作pdo,mysqli,總是返回0
//與功能PDO - >不行
function UserIsExist($name)
{
global $db;
$stmt = $db->prepare("SELECT id FROM tarskereso_users WHERE email = '$name' LIMIT 1");
$stmt->execute();
if ($stmt->fetchColumn() == 1) return 1;
else return 0;
}
//與庫MySQLi - >不工作
function UserIsExist($name)
{
global $db;
$stmt = $db->prepare("SELECT id,email FROM tarskereso_users WHERE email = ? LIMIT 1");
$stmt->bind_param('s', $name);
$stmt->execute();
$stmt->store_result();
if ($stmt->num_rows == 1)
return 1;
else
return 0;
$stmt->close();
}
//在Register.php
... other ..
if(UserIsExist($user) == 1)
$error_msg = "Is Exist";
else
{
$birthdate = $year.'.'.$month.'.'.$day;
CreateUser($user,$pass,$birthdate,$sex);
$error_msg = 'Success';
}
所以,功能不工作,我嘗試:
$stmt = $db->prepare("SELECT id,email FROM tarskereso_users WHERE email = ? LIMIT 1");
$stmt->bind_param('s', $name);
$stmt->execute();
$stmt->store_result();
if ($stmt->num_rows > 0)
... other ...
else
echo 'isnt exist...';
$stmt->close();
但不工作時,NUM_ROWS總是返回0。而在successfuly創建了PDO
看起來您的查詢正在查找電子郵件,但您正在將名稱傳遞給您的函數。這可能是問題嗎? – Maximus2012
你見過這個嗎? http://stackoverflow.com/questions/2700621/php-pdo-num-rows – Dallin
你是否已經完成了涉及所有變量的'var_dump()',包括數據庫連接變量? – jeroen