在PDO语句中是否可以有WHEN语句或IF语句?我试过以下,但它不工作PGM Mysql PDO WHEN或IF语句
$stmt = $conn->prepare('SELECT company_id, name, alias, fk_company_type as type, is_active as active FROM company WHERE (CASE WHEN :srchBy = "alias" THEN alias ELSE name END) LIKE :srchField');
$stmt->bindParam(':srchBy', $srchBy, PDO::PARAM_INT); //bind :srchField to $srchField in sql statement
$stmt->bindParam(':srchField', $srchField, PDO::PARAM_INT); //bind :srchField to $srchField in sql statement
表结构
company_id |23980471998218241 | 23980471998218242 |
fk_company_type |HQ |SITE |
name |JOHN PLUMBING HQ |JOHN PLUMBING - BRIDGE ST|
alias |CITY RD HQ |BRIDGE ST SERVICE |
is_active |1 |1 |
created_date |2015-04-18 19:35:32|2015-04-18 19:34:46 |
你去哪里把绑定PARAMS?请粘贴完整的代码。 –
fyi:你不能绑定标识符(表/列) – Ghost
感谢@Ghost的信息。 –