SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'exists' at line 1
Hi,
Am getting this error as in the subject line. Am new to PHP/MYSQL and am using PDO connection type. The error occurs at this line.
$row = $__conn->query("SELECT @exists AS exists")->fetch(PDO::FETCH_ASSOC);
Appreciate any help
Thanks
Ramani
<?php
/*function verifyemail($p_email) {*/
// echo "insde function - " . $p_email;
try {
// $pdo = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
echo "inside function";
$p_email = "ramani@gmail.com";
include 'db.php';
connectDB('msme_db',1) ;
// calling stored procedure command
$sql = 'CALL proc_test(:email,@exists)';
echo $sql ;
// prepare for execution of the stored procedure
$stmt = $__conn->prepare($sql);
// pass value to the command
$stmt->bindParam(':email', $p_email, PDO::PARAM_STR);
// execute the stored procedure
$stmt->execute();
print_r($stmt);
$stmt->closeCursor();
// execute the second query to get customer"s level
$row = $__conn->query("SELECT @exists AS exists")->fetch(PDO::FETCH_ASSOC);
if ($row) {
echo "inside if: " . $p_email ;
return $row !== false ? $row['exists'] : null;
} else {echo "else ";}
}
catch (PDOException $e) {
echo " in catch" ;
die("Error occurred:" . $e->getMessage());
}
closeDB(1);
// return null;
//}
//$email = "ramani@gmail.com";
//echo sprintf("Customer #%s is %s", $email, verifyemail($email));
//verifyemail($email) ;
?>