PHP PDO 与 SqlServer 存储过程不返回所有数据
我得到了一个这样调用的存储过程:
SP_REPORT_HOME 'param1','param2',1
它执行一堆我不知道的代码,尽管它返回一堆我需要使用的数据。它包含一些字段为空值,而其他字段则被完全填充(注意整行不为空,只有部分字段为空) 好吧,我在 Ubuntu 10.10 机器上使用 PDO 和 PHP 来获取该信息,我的 getReport 方法是:
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->connection 只是一个像这样创建的 PDO 实例:
$this->connection = new PDO(
"dblib:host=IP:PORT;dbname=DBNAME",
"LOGIN",
"PASS"
);
该方法返回包含数据但不包含行的数组包含空字段,有人知道为什么它不显示这些行吗?我真的需要他们。 我正在使用 PHP5.3 和 SQLServer 2008
I've been given an stored procedure that is called like this:
SP_REPORT_HOME 'param1','param2',1
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();
}
The $this->connection is just a PDO instance created like this:
$this->connection = new PDO(
"dblib:host=IP:PORT;dbname=DBNAME",
"LOGIN",
"PASS"
);
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看 http://php.net/manual/en/pdo.setattribute.php 用于 ATTR_ORACLE_NULLS 设置。我猜调整此设置将获得您想要的输出。
Check out http://php.net/manual/en/pdo.setattribute.php for the ATTR_ORACLE_NULLS setting. I'm guessing tweaking this setting will garner the output you desire.
好吧,最终程序出现了错误,尽管这确实很奇怪。
该过程在其步骤之一中创建一个临时表并插入我想要的数据。在我们这里使用的其他系统(用java构建)中,程序运行得很好,没有任何错误,并且所有数据都在那里。 SQL Server Management Studio 也会发生同样的情况,没有查询错误。
尽管在 php 中插入失败,因为它创建的表的字段不为空(尽管没有说这样做)。我发现这尝试使用 mssql 方式进行连接和查询。在 $connection->query() 调用中,它显示了插入错误,说我试图在非空字段中插入空值。但并没有停止剧本。导致结果中不包含具有空字段的行。 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...