Navaneetha Krishnan K
Navaneetha Krishnan K

Reputation: 237

String exact compare in Mysql

I have below columns in my Mysql DB,

 id, item_link, item_title, item_desc, created_date

In Item_title it contain the title of the item so I would like to check whether the item title is already present or not in the DB with below query as,

$title = "Egyptair \'Black Box\' Reveals Smoke Alert on Crashed Jet";

SELECT * FROM  `rss_feeds` WHERE  `item_title` =  '$title'

The above tiltle is already there in the db but even though by writing a query like this it returns

MySQL returned an empty result set (i.e. zero rows). ( Query took 0.0004 sec )

But this title is present in item_title column , could any one suggest me how to compare the string and retrieve the answer using Mysql Query.

Upvotes: 0

Views: 59

Answers (1)

Saty
Saty

Reputation: 22532

Better use bind and prepare statement for it . It will escape your string and prevent you form sql injection

$title = "Egyptair \'Black Box\' Reveals Smoke Alert on Crashed Jet";
$stmt = $mysqli->prepare("SELECT * FROM  `rss_feeds` WHERE  `item_title` =?");
 $stmt->bind_param('s', $title);
 /* execute prepared statement */
$stmt->execute();

Read http://php.net/manual/en/mysqli-stmt.bind-param.php

Upvotes: 1

Related Questions