Problem with PDO WHERE when using VARCHAR-columns in SQL Server

Viewed 100

We are upgrading our MS SQL Server from SQL Server 2012 to the current version. We are using PDO with M$ ODBC driver running on CentOS Linux. PHP version is 7.4.

The problem is that if there is a (prepared) condition like

WHERE variable = ? 

and variable is of type VARCHAR there comes an error

[Microsoft][ODBC Driver 17 for SQL Server][SQL Server]The data types varchar and text are incompatible in the equal to operator

An example code is like this:

$stmt = $db->prepare("SELECT * FROM Users WHERE user_login = ? AND user_application  = ?");
$stmt->execute([$login, $app]);

user_login and user_application are both VARCHAR-columns and $login and $app normal PHP string variables.

It wasn't a problem with the previous SQL server, the comparison went OK. I don't want to go through all the codebase to circumvent this in myriads of places - so - is there some setting somewhere (SQL server, ODBC-driver, PHP config, ...) where to set things "right" again?

1 Answers

Seems, it was sort of privileges error after the database migration. I removed the user that had come from restore operation and granted correct privileges again. Only, I am quite positive, I had done it already once. And I think there was no login errors when trying to use the database.

Sorry for dumb question. Though, I have always said, that there are no dumb questions, just dumb askers...

hank

Related