2016-01-16 62 views
2

當我使用ODBC只,全部順利連接黑斑羚使用ODBC和PHP PDO,串字段爲空

$dsn = "DSN=DingdongImpala;host=172.168.1.100;port=21050;database=mmdb;"; 
$user = ''; 
$password = ''; 
$conn = odbc_connect($dsn, $user, $password); 
$result = odbc_exec($conn, "select succount,failedcount,appid from t_mm_acc_date limit 1"); 
while($row = odbc_fetch_array($result)) { 
    print_r($row); 
} 

運行的結果是:

Array 
(
    [succount] => 0   //int 
    [failedcount] => 1  //int 
    [appid] => 202361  //string 
) 

但是當我使用PDO訪問ODBC ,String類型字段都爲空

$dsn = "odbc:DSN=DingdongImpala;Host=172.168.1.100;Port=21050;database=mmdb;"; 
$user = ''; 
$password = ''; 
$cnx = new PDO($dsn, $user, $password); 
$result = $cnx->query("select succount,failedcount,appid from t_mm_acc_date limit 1"); 
print_r($result->fetchObject()); 

結果是:

stdClass Object 
(
    [succount] => 100  //int 
    [failedcount] => 0  //int 
    [appid] =>    //string, empty 
) 

我試了很多情況下,只要我從黑斑羚中選擇String字段,結果將是空的,但是int字段是正常的。
我的系統環境:

centos 6 
PHP 5.3.6 
php-odbc-5.3.3 
unixODBC-2.2.14 
ClouderaImpalaODBC-2.5.29.1009-1.el6.x86_64.rpm 
+0

任何人誰可以幫我嗎? – tairyao

回答

0

我面臨着同樣的問題,因爲解決方法我鑄造字符串字段爲varchar,就像這樣:

select succount, failedcount, cast(appid as varchar(255)) from t_mm_acc_date limit 1