PHP pdo查询执行错误

时间:2013-01-15 13:08:05

标签: php sql-server pdo

我使用php和pdo以及pdo_dblib来执行长选择查询(在本例中)。如果我直接在sql中运行此查询,我收到结果,但如果我从php运行它我收到

207 General SQL Server error: Check messages from the SQL Server [207] (severity 16) [(null)]

我使用debugDumpParams查看准备后的查询是什么,但它只转储查询中的前500个字符,这可能是问题所在。这是一些配置参数还是这个错误?

操作系统:Slackware PHP:5.4.7 pdo_dblib - 由我自己编译 freetds - 来自http://slackbuilds.org/

Is there a maxium to the output of PDO::debugDumpParams?

修改

代码:

<?php
$dsn = 'dblib:host=XXXXXXXX;dbname=XXXXX';
$username='XXXXX';
$password='XXXXXXX';


$query = "select * from (
                select Row_Number() over (order by 
                order_status.id desc) as RowIndex,  
                order_status.id as ID,
                order_status.caller_type_id as CALLER_TYPE_ID,
                order_status.phone as PHONE,
                order_status.order_number as ORDER_NUMBER,
                order_status.caller_client_data_id as CLIENT_DATA_ID,
                order_status.caller_contact_phone_id as CALLER_CONTACT_PHONE_ID,
                order_status.record_date as DATE,
                order_status.call_date as CALL_DATE,
                order_status.call_time as jueCALL_TIME,
                order_status.username as USERNAME,
                client_data.ID as CALLER_ID,
                client_data.client_type_id as CLIENT_TYPE_ID,
                client_data.name as NAME,
                client_data.person as PERSON,
                client_data.country_id as COUNTRY_ID,
                client_data.city as CITY,
                client_data.street as STREET,
                client_data.street_number as STREET_NUMBER,
                client_data.living_complex as LIVING_COMPLEX,
                client_data.building as BUILDING,
                client_data.entrance as ENTRANCE,
                client_data.floor as FLOOR,
                client_data.apartment as APARTMENT,
                client_data.postal_code as POSTAL_CODE,
                client_data.description as DESCRIPTION,
                client_data.email as EMAIL,
                country.name as COUNTRY,
                client_type.type as CLIENT_TYPE,
                caller_type.name as CALLER_TYPE,
                contact_phone.phone as CALLER_CONTACT_PHONE
                from order_status order_status
                inner join client_data client_data on client_data.id = order_status.caller_client_data_id
                inner join client_type client_type on client_type.id = client_data.client_type_id
                inner join country country on country.id = client_data.country_id
                inner join caller_type caller_type on caller_type.id = order_status.caller_type_id
                inner join contact_phone on contact_phone.id = order_status.caller_contact_phone_id
             where 1=1 ) as Sub Where Sub.RowIndex >= ? and Sub.RowIndex < ?";


$db = new PDO($dsn, $username, $password);
$prepare = $db->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
$bind = array(1, 11);
if (!$prepare->execute($bind)) {
    $prepare->debugDumpParams();
} else {
    echo "success";
}

输出:

SQL: [1841] select * from (
                select Row_Number() over (order by 
                order_status.id desc) as RowIndex,  
                order_status.id as ID,
                order_status.caller_type_id as CALLER_TYPE_ID,
                order_status.phone as PHONE,
                order_status.order_number as ORDER_NUMBER,
                order_status.caller_client_data_id as CLIENT_DATA_ID,
                order_status.caller_contact_phone_id as CALLER_CONTACT_PHONE_ID,
                order_status.record_date as DATE,
                order_status.call_date as CALL_DATE,
                order_status.call_time as jueCALL_T
Params:  2
Key: Position #0:
paramno=0
name=[0] ""
is_param=1
param_type=2
Key: Position #1:
paramno=1
name=[0] ""
is_param=1
param_type=2

2 个答案:

答案 0 :(得分:0)

在服务器上为PDO进程设置TDSDUMP环境变量。该日志将捕获您需要的缺失消息和详细信息。

答案 1 :(得分:0)

我为失去你的时间而道歉。我发现了我的错误 - 连接到MSSQL中的两个不同的数据库。

P.S。如果我在freetds配置中启用转储文件,我仍然会出现Segmentation fault错误,但我仍然不知道如何将debugDumpParams设置为输出超过500个字符Is there a maxium to the output of PDO::debugDumpParams?