Reputation: 164
i'm currently building the database for my system and wanted to create an abstraction of the db by using stored function and stored procedures for every request from php. my question is i have a function that checks if an email exists and returns true if the email exist and false otherwise. now how can i check the Boolean return value after a pdo call in php. my php code is
$connection = new DB_CONNECTION();
$sql = "SELECT email_exists(:email) ";
$placeholder = array(":email" => $userMail );
$statement = $connection->prepare_query( $sql );
$result = $statement->execute($placeholder);
$result = $statement->fetch();
echo $result;
Upvotes: 2
Views: 581
Reputation: 23892
Just give the returned value an alias
and it is accessible by that index in the array.
$connection = new DB_CONNECTION();
$sql = "SELECT email_exists(:email) as da_count ";
$placeholder = array(":email" => $userMail );
$statement = $connection->prepare_query( $sql );
$result = $statement->execute($placeholder);
$result = $statement->fetch();
echo $result['da_count'];
You can conditionalize that as needed;
if(empty($result['da_count'])) {
echo 'Email doesnt exist';
} else {
echo 'Email does exist';
}
Upvotes: 1