在PHP中,带有like返回值的SQL查询有所不同 [英] SQL Query with like returns differently in php

查看:136
本文介绍了在PHP中,带有like返回值的SQL查询有所不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


已解决:我测试过将查询作为存储过程编写,并且
仍然在php中报告错误。最终我发现,因为
我有一些带有空值的列,PHP却在奇怪地读取它们。
令人失望地得知Perl处理得更好,但是很好。

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.

我在adodb上使用PHP 5.3.3可以访问MS SQL Server2012。我的大多数查询都很好,但是我试图使用通配符进行完全联接。

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.

以下是打开部分:

on a_table.hostname LIKE '%' + r_table.Hostname + '%' 
OR '%' + a_table.hostname like r_table.Name + '%'

在SQL Studio中执行查询时,我得到1224条记录。
在PHP,2406中。我已经查看了sql服务器上的日志,并且该服务器正在运行的查询是准确的,并且在复制和粘贴后返回了预期的/正确的结果数。

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.

如果我在PHP中编辑查询并删除串联的%s,则结果与直接执行查询一致(如果通配符也从中删除了) 。

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).

我已经用PHP的mssql函数和adodb测试了查询,结果相同。

I've tested the query with PHP's mssql functions and adodb with the same results.

编辑:我刚刚使用三种方法测试了查询:通过Perl,Sql Studio和PHP。佩尔SQL Studio是相同的-PHP仍然是错误的。

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.

推荐答案

我测试过将查询作为存储过程编写,并且仍然报告错误地在PHP中。最终我发现,因为我有一些带有null的列,PHP却奇怪地读取了它们。

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.

这篇关于在PHP中,带有like返回值的SQL查询有所不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆