Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php bindparam不工作-PDO_Php_Pdo - Fatal编程技术网

Php bindparam不工作-PDO

Php bindparam不工作-PDO,php,pdo,Php,Pdo,我正在尝试获取rss脚本提供的链接 使用bindParam的我的代码 $items = count($return_data->channel->item); for($i=0; $i<1; $i++){ $link = $desc = $return_data->channel->item[$i]->link; $title = $desc = $return_data->channel->item[

我正在尝试获取rss脚本提供的链接

使用bindParam的我的代码

$items = count($return_data->channel->item);
     for($i=0; $i<1; $i++){
         $link = $desc = $return_data->channel->item[$i]->link;
         $title = $desc = $return_data->channel->item[$i]->title;
         echo $link;
         echo '<hr>';
         // PDO query -> check if news already is in database
         $q1 = $db->prepare("SELECT * FROM runescapenews WHERE link=':link'");
         $q1->bindParam(':link', $link);
         $q1->execute();
         $r1 = $q1->rowCount();
         echo $r1;
         echo '<hr>';
         if($r1 == '0' ){
             echo '0 - Not working';
         }else{
            while($res1 = $q1->fetch(PDO::FETCH_ASSOC)) {
                echo $res1['title'];
            }                 
         }
     }
但是当我将
link=':link'
更改为
link='$link'
时,我的结果将是:

http://services.runescape.com/m=news/a=135/barrows---rise-of-the-six
1
Barrows - Rise of the Six

所以我的问题是。当使用$link by prepare时,如何让它与bindParam一起工作,并且仍然获得我在结果上得到的结果?

$q1=$db->prepare(“从runescapenews中选择*,其中link=:link”)

删除'because bindParam dos automatically'如果您在答案中解释了差异就好了。'link not':link'因为PDO准备的语句可以这样做way@JoniSalmi哇!谢谢它的工作!对不起,我的问题太离谱了。@JoniSalmi:我很清楚PDO准备的报表是如何工作的。请参阅我的个人资料。:)我的观点是,一行没有解释的代码是一个蹩脚的答案。你放在评论里的东西更有帮助,但是评论可能会消失。如果答案本身包含这些信息就更好了。
http://services.runescape.com/m=news/a=135/barrows---rise-of-the-six
1
Barrows - Rise of the Six