ODBC_Exec正常工作时出现PDO错误 [英] PDO Error when ODBC_Exec works correctly

查看:177
本文介绍了ODBC_Exec正常工作时出现PDO错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目要转换,到目前为止,用一个脚本有几个奇怪的结果.转换是从过程ODBC到PDO.执行旧的和新的查询构造时,我具有以下不同的结果集.

I have a project I am converting and am having several weird results with one script so far. The conversion is from procedural ODBC to PDO. I have the following differing result sets when I perform the old and new query constructs.

$con = odbc_connect("database","user,"pass");
if(!$con){
    exit("error");
}
    $sql = "SELECT column,column2 FROM table WHERE column3=number AND ((column2 Like '%hold%') OR (column2 Like '%panic%'))";
$result = odbc_exec($con,$sql); 
if(!$result)
    exit("error");
$temp = array();
    while($row = odbc_fetch_array($result)){
        if(($preferedKey !="")&&isset($row[$preferedKey])){
            $temp[$row[$preferedKey]] = $row;
        }
        else {
            array_push($temp, $row);
        }
    }
odbc_close($con);
return $temp;

这将返回一个多维数组

Array(
[0] => Array
    (
        [column] => 026
        [column2] => COLLECTION HOLD UP 
    )

[1] => Array
    (
        [column] => 027
        [column2] => MORTGAGE HOLD UP
    )

[2] => Array
    (
        [column] => 028
        [column2] => HOLD UP 
    )
)

当我使用PDO来获取信息时,所有其他变量/参数都保持不变,我得到以下信息(也包括代码):

When I use PDO to get the information with all other variables/parameters kept the same I get the following (code included as well):

try{
    $data = PDO_Connect($database)->query($sql)->fetchAll(PDO::FETCH_ASSOC);

    return ((count($data)==1&&$assoc==false) ? $data[0] : ($preferedKey!="" ? (isset($data[0][$preferedKey]) ? changeKey($data,$preferedKey) : $data) : $data));
} catch(PDOException $e){
    die($e);
    //error_redirect($e);   
}

Array(
[0] => Array
    (
        [column] => 026
        [column2] => 
    )

[1] => Array
    (
        [column] => 027
        [column2] => 
    )

[2] => Array
    (
        [column] => 028
        [column2] => 
    )
)

如果我删除column并仅选择column2,则第一个方法返回:

If I remove column and just select column2, first method returns:

Array(
[0] => Array
    (
        [column2] => COLLECTION HOLD UP 
    )

[1] => Array
    (
        [column2] => MORTGAGE HOLD UP
    )

[2] => Array
    (
        [column2] => HOLD UP 
    )
)

PDO方法错误:

PDOException:SQLSTATE [SL009]:<>:0 [unixODBC] [Driver Manager]在/build/php7.0-x25jsn/php7.0处调用SQLFetch或SQLFetchScroll(SQLFetchScroll [0]之前,未绑定任何列-7.0.13/ext/pdo_odbc/odbc_stmt.c:559)

PDOException: SQLSTATE[SL009]: <>: 0 [unixODBC][Driver Manager]No columns were bound prior to calling SQLFetch or SQLFetchScroll (SQLFetchScroll[0] at /build/php7.0-x25jsn/php7.0-7.0.13/ext/pdo_odbc/odbc_stmt.c:559)

我已经成功转换了网站的其余大部分内容,并且找不到任何可能发生的原因/原因.

I've successfully converted most of the rest of the site, and cannot find any cause/reason this should be happening.

搜索后,我尝试将LOBINTColumn作为LOB来查看发生了什么:

After searching, I tried to bindColumn as LOB to see what happened:

$sql = "SELECT column,column2 FROM table WHERE column3=number AND ((column2 Like '%hold%') OR (column2 Like '%panic%'))";
$stmt = PDO_Connect($database)->prepare($sql);
$stmt->bindColumn("Description",$desc,PDO::PARAM_LOB)
$stmt->execute();
while($data = $stmt->fetch(PDO::FETCH_BOUND)){
    fpassthru($desc);
    darray(get_defined_vars());
}

我得到fpassthru()期望参数1为资源,给定为空

I get fpassthru() expects parameter 1 to be resource, null given

从$ sql中删除列会给我同样的错误,即没有绑定列.

removing column from $sql gives me the same error of no bound columns.

我也尝试了CAST(column2 as varchar),它的值为1 强制转换为INT会引发错误,但错误中有我需要数据库提供的数据

I also tried CAST(column2 as varchar) and it gets a value of 1 Casting to INT throws an error as expected, but has the data I need from the DB in the error

错误-157:无法将'COLLECTION HOLD UP'转换为整数

Error -157: Cannot convert 'COLLECTION HOLD UP ' to a integer



编辑@中部16:40

经过几个小时的搜索,发现了几个有关长varchar不起作用的php错误报告,只是返回了空值.其中之一已经开放了将近10年.我不确定在严格的PDO环境中是否可以解决此问题.



EDIT @ 16:40 Central

Few more hours searching and found a couple php bug reports about long varchars not working, just returning null values. One of them has been open for almost 10 years. I'm not sure this problem is solvable in a strict PDO environment.

我将不得不尝试使用PDO获取信息,如果返回的结果为空,则尝试使用ODBC_Exec,然后仅当两者都为null时,它才是真正为null的列或不存在任何记录.

I'll have to try to get info with PDO, and if a null result is returned, try with ODBC_Exec, and then only if both are null, it is a truly null column or no records exist.

这看起来正确吗?

推荐答案

->

if (1) {
    // ......
} else {
    // ......
}

重新编译PDO_ODBC,它神奇地工作

re-compile PDO_ODBC and it works magically

这篇关于ODBC_Exec正常工作时出现PDO错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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