问题
Solved: I tested writing the query as a stored procedure and again it still reported incorrectly in php. Ultimately I found out that because I have some columns with nulls PHP was reading them strangely. Disappointing to learn that Perl handled this better, but oh well.
I'm using PHP 5.3.3 with adodb to access MS SQL server 2012. Most of my queries have been fine, but I'm trying to do a full join with wildcards.
Here's the on portion:
on a_table.hostname LIKE '%' + r_table.Hostname + '%'
OR '%' + a_table.hostname like r_table.Name + '%'
When I execute the query in SQL Studio, I get 1224 records. In PHP, 2406. I've looked at the logs on the sql server and the query it's running is accurate, and when copied and pasted returns the expected/correct number of results.
If I edit the query in my PHP and remove the concatenated %s the results are then consistent with executing the query directly (if the wildcards are removed from that as well).
I've tested the query with PHP's mssql functions and adodb with the same results.
EDIT: I've just tested the query with count three ways: via Perl, Sql studio, and PHP. Perl & SQL studio are the same - PHP is still wrong.
回答1:
I tested writing the query as a stored procedure and again it still reported incorrectly in php. Ultimately I found out that because I have some columns with nulls, PHP was reading them strangely.
来源:https://stackoverflow.com/questions/15576170/sql-query-with-like-returns-differently-in-php