Currently, I create an apps with a login function. To connect from android to MySQL database, I use PHP. When I use MySQLi, everything is okay. But when I convert to PDO, The error will appear the same as my question's title. Can anyone knows what is the problem? Below is my PHP code:
<?php
require_once 'configPDO.php';
$response = array();
if(isTheseParametersAvailable(array('badgeid', 'pwd'))){
$badgeid = $_POST['badgeid'];
$pwd = $_POST['pwd'];
$stmt = $conn->prepare("SELECT badgeid, email, fullname, roles_id, team_id FROM users WHERE badgeid = :badgeid AND pwd = :pwd AND roles_id = 3");
// $stmt->bind_param("ss",$badgeid, $pwd);
$stmt->bindParam(':badgeid',$badgeid,PDO::PARAM_STR);
$stmt->bindParam(':pwd',$pwd,PDO::PARAM_STR);
$stmt->execute();
//$stmt->store_result();
if($stmt->rowCount() > 0){
$stmt->bindParam($badgeid, $email, $fullname, $roles_id, $team_id);
$stmt->fetch();
$user = array(
'badgeid'=>$badgeid,
'email'=>$email,
'fullname'=>$fullname,
'roles_id'=>$roles_id,
'team_id'=>$team_id
);
$response['error'] = false;
$response['message'] = 'Login successfull';
$response['user'] = $user;
}else{
$response['error'] = false;
$response['message'] = 'Invalid username or password';
}
}
echo json_encode($response);
function isTheseParametersAvailable($params){
foreach($params as $param){
if(!isset($_POST[$param])){
return false;
}
}
return true;
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…