带有SqlServer存储过程的PHP PDO不会返回所有数据 [英] PHP PDO with SqlServer Stored Procedure doesn't return all the data

查看:335
本文介绍了带有SqlServer存储过程的PHP PDO不会返回所有数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已经给我提供了一个存储过程,如下所示:

I've been given an stored procedure that is called like this:

SP_REPORT_HOME 'param1','param2',1

它执行一堆我不知道的代码,尽管它返回了我需要使用的一堆数据.它包含一些具有空值的字段,而其他字段则完全填充(请注意,整行不为空,只有某些字段) 好吧,我在Ubuntu 10.10计算机上使用PDO和PHP来获取该信息,我的getReport方法是:

It executes a bunch of code i'm not aware of, although it return a bunch of data I need to use. It contains some fields with null values, while others are fully filled (note that the entire row is not null, only some fields) Well I'm using PDO and PHP on an Ubuntu 10.10 machine to get that information, my getReport method is:

public function getReport($empresa1, $empresa2, $num) {
    $ds = $this->connection->prepare('SP_REPORT_HOME ?,?,?');
    $ds->bindParam(1, $empresa1, PDO::PARAM_STR, 4);
    $ds->bindParam(2, $empresa2, PDO::PARAM_STR, 4);
    $ds->bindParam(3, $num, PDO::PARAM_INT, 4);
    $ds->execute(); 
    return $ds->fetchAll();
}

$ this->连接只是这样创建的PDO实例:

The $this->connection is just a PDO instance created like this:

$this->connection = new PDO(
        "dblib:host=IP:PORT;dbname=DBNAME", 
        "LOGIN", 
        "PASS"
    );

该方法返回包含数据的数组,但没有包含空字段的行,有人知道为什么它不显示这些行吗?我真的很需要他们 我正在使用PHP5.3和SQLServer 2008

The method returns the array containing the data without the rows that contain null fields, anyone know why it doesn't show these rows? I really need them. I'm using PHP5.3 and SQLServer 2008

推荐答案

好吧,尽管确实很奇怪,但最终还是出现了程序错误.

该过程在其步骤之一中将创建一个临时表并插入所需的数据.在我们在这里使用的其他系统(使用Java内置)中,该过程运行良好,完全没有错误,并且所有数据都在那里. SQL Server Management Studio也会发生同样的情况,没有查询错误.

虽然在php中插入失败,因为它创建的表不包含空字段(尽管据说这样做不是这样).我发现这尝试使用mssql方式进行连接和查询.在$ connection-> query()调用中,它显示一个插入错误,表示我试图在一个非null字段中插入null.但是没有停止脚本.结果中没有带空字段的行. pdo版本可能有相同的问题,但是抑制了错误消息.

好了,我们更改了程序,使表的创建指示空字段,但仍然不知道为什么它可以在所有其他系统中工作,而在php中,它们对这些字段使用了另一个默认值...

Well, ended up there was an error on the procedure, although it is really strange.

The procedure, in one of its steps create a temporary table and inserts the data I want. In the other systems we use here (built in java) the procedure works just fine, no errors at all and all the data is there. The same happens for SQL Server Management Studio, no query errors.

Although in php the insert fails because it creates the table with not null fields (although it is not said to do so). I found this trying the connection and query using the mssql way. In the $connection->query() call it showed an insert error, saying I was trying to inset null in a not null field. Didn't stop the script though. Resulting in the result without the rows with null fields. The pdo version probably had the same problem but was suppressing the error message.

Well, we changed the procedure so the table creation indicates null fields, but still, we have no clue on why it worked in all the other systems and in php it used another default for these fields...

这篇关于带有SqlServer存储过程的PHP PDO不会返回所有数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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