我在使用带有PDO的函数AES_ENCRYPT时遇到问题,当我使用下面的SQL语句:pass和:key作为绑定参数时,我得不到数据库的匹配。但是,如果我将它们取出并直接放入SELECT语句中,我得到一个COUNT为1的结果是正确的。
我是否将这些错误地嵌入到语句中,还是有另一种方法可以使我的选择函数与AES_ENCRYPT函数一起正常工作?该功能可以直接使用直线参数,例如
SELECT * FROM users WHERE name =:name AND email =:email
$query[] = "SELECT COUNT(1) FROM users WHERE active=1 AND username=:username AND password=AES_ENCRYPT(:pass,:key);";
$query[] = array(
'username' => $username,
'pass' => $pass,
'key' => $key );
list($exists) = select( $query, true );
function select( array &$query, $one=FALSE ) {
try {
$stmt = $this->PDO->prepare( $this->named_queries( $query[0] ) );
foreach( $query[1] as $k=>$v ) {
$stmt->bindParam( ":$k", $v );
}
$stmt->execute();
$query = array(); # If the query is from a loop this prevents only the first loop's SELECT from being used.
if( $one ) {
$return = $stmt->fetch();
}else{
$return = $stmt->fetchAll();
}
return $return;
}catch( PDOException $e ) {
if( $this->test )
self::print_error( __METHOD__, $e->getMessage() );
return false;
}
}