I transfer from MYSQL in MSSQL the project. Faced a problem in the prepared requests. If earlier I used in MYSQL

$stmt = $db->prepare("SELECT 1 as something, t.id, creator_id, status, fire, u.firstname as firstname, u.surname as surname, category, responsible, t.dept, FROM tickets as t LEFT OUTER JOIN users as u ON t.responsible = u.id WHERE creator_id = :uid AND status = 'Статус 1' UNION SELECT 2 as something, t.id, creator_id, status, fire, u.firstname as firstname, u.surname as surname, category, responsible, t.dept, FROM tickets as t LEFT OUTER JOIN users as u ON t.responsible = u.id WHERE creator_id = :uid AND (status = 'Статус 2' OR status = 'Статус 3' OR status = 'Статус 4') "); 

$ stmt-> bindParam (': uid', $ uid, PDO :: PARAM_INT);

All was good.

But in a situation with MSSQL, only the usual query is processed if you substitute values ​​manually, and when prepare, an error is thrown: [Microsoft] [ODBC Driver 11 for SQL Server] COUNT

* Moreover, I noticed that if you do not use UNION, then there are no errors. I leave only the first SELECT and there are no errors.

I would be glad if anyone has experience how to get around such an unpleasant thing.

    1 answer 1

    In mysql, if you turn off emulation, it would be the same error.

    In native mode, identical placeholder names are not supported . So you need to do two different placeholders and tie them too twice, with the same value.

    • bingo! Thank you very much, they ravaged it. - Andrew Medvedev