I'm using the POP PHP Framework ( http://www.popphp.org/ ). I'm trying to write a prepared statement to check if an email address already exists or not in the database.
Digging through the manual I can't find any example on how to compare a text string with a result in the database, only numbers. To do that it isn't that hard, just like:
$sql->select()->where()->greaterThanOrEqualTo('id', '?');
But comparing if an email address exists or not, I can't find the solution for. Below is my incomplete code. Line 6 is where I try to do a comparison. Getting no error because it isn't supported. The mail address exists in the database, so that isn't any problem.
// Check if user already exists
$db = Db::factory($this->type, $this->creds);
// Create a prepared statement
$sql = new Sql($db, 'user');
$sql->select()->where()->like('email', '?');
// Prepare the statement, bind the parameters and execute
$db->adapter()->prepare('email', '?');
$db->adapter()->bindParams(array('email' => $post['email']));
$db->adapter()->execute();
print_r($db->adapter()->fetch());
if($db->adapter()->fetch() != false)
{
$error['userExists'] = "User exists";
echo "Exists";
}
How should I do to get this code complete?
我不了解POPPHP,但是在检查API之后 ,您似乎正在寻找的是Pop\\Db\\Sql\\Predicate::equalTo($column, $value, $combine)
,例如:
$sql->select()->where()->equalTo('email', '?');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.