user3189734
user3189734

Reputation: 665

concat condition not working in php pdo but running in mySQL

Running the following query works perfectly in my user search, within mySQL on phpmyadmin.

SELECT user_id, fname, lname, email FROM users WHERE fname LIKE '%Scott James%' OR lname LIKE '%Scott James%' OR CONCAT(fname,' ',lname) LIKE '%Scott James%'

However, if I try and run this through php on production environment, it seems to fall over. Anyone got any ideas?

$word = $_REQUEST['search'];

$search_query='SELECT user_id, fname, lname, email FROM users WHERE fname LIKE :search OR lname LIKE :search OR CONCAT(fname,' ',lname) LIKE :search';

$stmt= $conn->prepare($search_query);
$stmt->execute(array(
  ':search'   => '%'.$word.'%',
  ':user_id'   => $user_id 
    ));

Upvotes: 0

Views: 490

Answers (1)

Your Common Sense
Your Common Sense

Reputation: 157916

  1. make sure PDO is in emulation mode to allow multiple parameters with same name
  2. Get rid of this ':user_id' => $user_id stuff.
  3. Make sure PDO is in exception mode and you can see PHP errors

Upvotes: 1

Related Questions