REGEXP与PDO Mysql [英] REGEXP With PDO Mysql

查看:95
本文介绍了REGEXP与PDO Mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在PDO Mydql中使用REGEXP,但是出了些问题

I am trying to use REGEXP in PDO Mydql but there is something wrong

function artist_list($artist){
            global $DBH;
$STH = $DBH->prepare("SELECT songs ,image ,artist,album,r_year
            FROM english_fm
            WHERE artist REGEXP \"^[:artist]\" 
             GROUP BY artist order by slno");
            $STH->bindValue(":artist" , "$artist", PDO::PARAM_STR); 
            $STH->execute();
            $STH->setFetchMode(PDO::FETCH_ASSOC);
            return $STH;
            $DBH = Null;
        } 

这在我使用REGEXP \"^[:artist]\"时不起作用,但是如果我使用

this is no working when i am using REGEXP \"^[:artist]\" but if i use

REGEXP \"^[$artist]\" 

有效

function artist_list($artist){
                global $DBH;
    $STH = $DBH->prepare("SELECT songs ,image ,artist,album,r_year
                FROM english_fm
                WHERE artist REGEXP \"^[$artist]\" 
                 GROUP BY artist order by slno");
                $STH->bindValue(":artist" , "$artist", PDO::PARAM_STR); 
                $STH->execute();
                $STH->setFetchMode(PDO::FETCH_ASSOC);
                return $STH;
                $DBH = Null;
            } 

请帮助

推荐答案

您不能使用这样的准备好的语句.声明占位符时,您避免做任何相关的事情在其上,将其保留为占位符的定义.因此,例如,您可以这样使用它:

You cannot use the prepared statements like that. When you declare a placeholder, you avoid doing any related stuff on them, leaving this to the placeholder value definition. So, for instance, you may use it like that:

$STH = $DBH->prepare("SELECT songs ,image ,artist,album,r_year
            FROM english_fm
            WHERE artist REGEXP :artist
            GROUP BY artist order by slno");
            $STH->bindValue(":artist" , "^[$artist]", PDO::PARAM_STR); 

这篇关于REGEXP与PDO Mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆