Reputation: 11
I like to combine two columns in my where clause:
$stmt = $this->_db->prepare('SELECT password, firstname, lastname FROM eymployees WHERE (firstname + ' ' + lastname) LIKE :username');
This is the error I get:
Parse error: syntax error, unexpected '' . lastname) LIKE :username'' (T_CONSTANT_ENCAPSED_STRING)
Is there a way I can add a space in between firstname
and lastname
?
Thanks for help!
Upvotes: 1
Views: 53
Reputation: 34
$stmt = $this->_db->prepare('SELECT password, firstname, lastname FROM eymployees
WHERE CONCAT(CONCAT(firstname, ' '), lastname) LIKE :username');
if firstname and lastname is of char type, then use rtrim function
Upvotes: 0
Reputation: 7766
You can use CONCAT()
function
$stmt = $this->_db->prepare('SELECT password, firstname, lastname FROM eymployees
WHERE CONCAT(firstname, ' ', lastname) LIKE :username');
Upvotes: 3