I'm converting the queries from mysql to pdo to run on mssql and I have this query that is driving me nuts:
UPDATE cms_users SET lastlogin = GETDATE() WHERE id = '1'
For some reason it breaks when I run it through the PDO on the PHP application but when I run it on the Microsoft SQL Server Management Studio it executes.
This is the line where I'm running the query:
$this->db_val->query($Query,$this->db_val) or die("Error in Update Query <br> ".$Query."<br>");
And when i added some attributes to capture the error from PDO by putting this code in:
$this->db_val->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
I got this error:
Uncaught exception 'PDOException' with message 'SQLSTATE[42S22]: [Microsoft][SQL Server Native Client 11.0][SQL Server]Invalid column name 'UPDATE cms_users SET lastlogin = GETDATE() WHERE id = '1''
Not sure which is the invalid column name, i tried putting the column names in `` but that didn't work as well.
UPDATE:
If this helps, I'm getting the same issue with a different query:
DELETE FROM cms_audittrail WHERE transactiondate <= '2015-02-26'
That also works on the sql studio but is not working through the php application. I am getting:
Uncaught exception 'PDOException' with message 'SQLSTATE[42S22]: [Microsoft][SQL Server Native Client 11.0][SQL Server]Invalid column name 'DELETE FROM cms_audittrail WHERE transactiondate <= '2015-02-26''