Skip to main content
Tweeted twitter.com/#!/StackDrupal/status/274906278902525953
deleted 86 characters in body; edited title
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

Why is this query is failing?

I'm using concantCONCAT in a join, its. It works well in phpmyadmin, then I converted it into PDO statement using db_select.

The strange thing I noticed itPHPMyAdmin, but the follwoingequivalent Drupal query is failingdoesn't work.

$query->join('taxonomy_term_data', 'td', 'sbc.tname LIKE CONCAT( td.name,  "%\" ) AND td.vid = sbc.vid');

withThis query causes the following error,:

PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column '%' in 'on clause'

However, the following query works fine and gives me the result,.

$query->join('taxonomy_term_data', 'td', 'sbc.tname LIKE CONCAT( td.name,  \'%\' ) AND td.vid = sbc.vid');

The only difference between the two queries is the string quotes,: In the first one I used double quotes to wrap % and In%; in the second one I used single quotes.

But phpmyadminPHPMyAdmin gives me the result whether the % is wrapped with single quotes, or double quotes. (Actually, it should.)

I think there is something I'm missing. I'm just curious to know what it is.

Why this query is failing?

I'm using concant in join, its works well in phpmyadmin, then I converted it into PDO statement using db_select.

The strange thing I noticed it, the follwoing query is failing

$query->join('taxonomy_term_data', 'td', 'sbc.tname LIKE CONCAT( td.name,  "%\" ) AND td.vid = sbc.vid');

with the following error,

PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column '%' in 'on clause'

However the following query works fine and gives me the result,

$query->join('taxonomy_term_data', 'td', 'sbc.tname LIKE CONCAT( td.name,  \'%\' ) AND td.vid = sbc.vid');

The only difference between the two queries is the string quotes, In the first one I used double quotes to wrap % and In the second one I used single quotes.

But phpmyadmin gives me the result whether the % is wrapped with single quotes or double quotes (Actually it should)

I think there is something I'm missing. I'm just curious to know what it is.

Why is this query failing?

I'm using CONCAT in a join. It works well in PHPMyAdmin, but the equivalent Drupal query doesn't work.

$query->join('taxonomy_term_data', 'td', 'sbc.tname LIKE CONCAT( td.name,  "%\" ) AND td.vid = sbc.vid');

This query causes the following error:

PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column '%' in 'on clause'

However, the following query works fine.

$query->join('taxonomy_term_data', 'td', 'sbc.tname LIKE CONCAT( td.name,  \'%\' ) AND td.vid = sbc.vid');

The only difference between the two queries is the string quotes: In the first one I used double quotes to wrap %; in the second one I used single quotes.

PHPMyAdmin gives me the result whether the % is wrapped with single quotes, or double quotes. (Actually, it should.)

I think there is something I'm missing. I'm just curious to know what it is.

Source Link
Mathankumar
  • 3.4k
  • 25
  • 35

Why this query is failing?

I'm using concant in join, its works well in phpmyadmin, then I converted it into PDO statement using db_select.

The strange thing I noticed it, the follwoing query is failing

$query->join('taxonomy_term_data', 'td', 'sbc.tname LIKE CONCAT( td.name,  "%\" ) AND td.vid = sbc.vid');

with the following error,

PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column '%' in 'on clause'

However the following query works fine and gives me the result,

$query->join('taxonomy_term_data', 'td', 'sbc.tname LIKE CONCAT( td.name,  \'%\' ) AND td.vid = sbc.vid');

The only difference between the two queries is the string quotes, In the first one I used double quotes to wrap % and In the second one I used single quotes.

But phpmyadmin gives me the result whether the % is wrapped with single quotes or double quotes (Actually it should)

I think there is something I'm missing. I'm just curious to know what it is.