Home:ALL Converter>Full-text search in PDO using parameters

Full-text search in PDO using parameters

Ask Time:2015-06-29T19:05:52         Author:user3079872

Json Formatter

I am trying to do a full text search using PDO with a parameter.

If I use the sql query with a constant variable, the select works, and it returns the correct list from the MySQL database.

But the code I have to select on a parameter does not return anything.

Here is my code:

<?php
 $conn  = new PDO ("mysql:host=$servername;dbname=$dbname", $username, $password); 
 $conn ->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 

 $val = $_REQUEST['val'];
 $sth = $conn ->prepare('SELECT UserID FROM Users WHERE MATCH (First, Last) AGAINST (:val IN BOOLEAN MODE');

 $sth->execute(array(':val' => $val));
 $friends = $sth->fetchAll(PDO::FETCH_ASSOC);
 $json=json_encode($friends);
 echo $json;
 ?>

From my app I call the above function as follows:

 smUID = [NSString stringWithFormat:@"http://www.myServerName.co.uk/searchQuery.php?val=%@", searchString];
 dataSMURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:smUID]];
 smUIDResult = [[NSString alloc] initWithData:dataSMURL encoding:NSUTF8StringEncoding];

I don't think my PDO is right as it is not returning any values, but I can't see what is wrong or what else it needs.

Author:user3079872,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/31114073/full-text-search-in-pdo-using-parameters
yy