0

I'm trying to get the link that it given by my rss script.

My Code with 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'];
            }                 
         }
     }

Now the problem is that my result is not working :

 http://services.runescape.com/m=news/a=135/barrows---rise-of-the-six
 0
 0 - Not working

But when i change the link = ':link' to link='$link' my result will be :

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

So my question is. How can i get it working with bindParam and still get the result i am getting on the result when using $link by prepare?

1 Answer 1

2

$q1 = $db->prepare("SELECT * FROM runescapenews WHERE link=:link");

Sign up to request clarification or add additional context in comments.

6 Comments

Drop the ' because bindParam does it automatically
It'd be good if you explained the difference within the answer.
:link not ':link' because PDO prepared statements work this way
@JoniSalmi o wow! Thanks its working! sorry for my noobie question.
@JoniSalmi: I'm well aware of how PDO prepared statements work. See my profile. :) My point was that a line of code with no explanation is a crappy answer. The stuff you're putting in the comments is a bit more helpful, but comments can disappear. It'd be better if the answer itself included that info.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.