odbc_connect无法在unixODBC(LINUX)上运行

时间:2014-01-20 11:04:48

标签: php linux unixodbc

我已将此代码包含在当前活动主题的 functions.php 中并且运行正常(即:我先在服务器上载.mdb文件,然后从文件中读取表格)在 WINDOWS PLATFORM 。这和我们使用MySQL DB一样简单。

$dbName = $uploadfile;

$conn = odbc_connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=$dbName", "", "");


if($conn != null){

//echo "";exit;

// reading all the tables (data) from mdb file uploaded
$cdc_trans = odbc_exec($conn, "SELECT * FROM axs_web_cdc_trans");
$dealers = odbc_exec($conn, "SELECT * FROM axs_web_dealers");
$web_item = odbc_exec($conn, "SELECT * FROM axs_web_item");
$parties = odbc_exec($conn, "SELECT * FROM axs_web_parties");
$trans = odbc_exec($conn, "SELECT * FROM axs_web_trans");
$voch = odbc_exec($conn, "SELECT * FROM axs_web_voch");




// insert for axs_web_cdc_trans
while($row = odbc_fetch_array($cdc_trans)){
    //break;
        $cdc_trans_date = $row['CDC_TRANS_DATE'];
        $agent_code = $row['AGENT_CODE'];
        $party_user_code = $row['PARTY_USER_CODE'];
        $nature = $row['NATURE'];
        $quantity = $row['CDC_QTY'];
        $item = $row['TRANS_ITEM_SYMBOL'];
        $us_qty = $row['UNSETTLED_QTY'];


        $sql = "INSERT INTO axs_web_cdc_trans (CDC_TRANS_DATE,AGENT_CODE,PARTY_USER_CODE, NATURE, CDC_QTY,TRANS_ITEM_SYMBOL,UNSETTLED_QTY) VALUES ('$cdc_trans_date', '$agent_code', '$party_user_code', '$nature', '$quantity', '$item', '$us_qty')";


        mysql_query($sql) or die("Error: ".mysql_error());
    }

    // insert for axs_web_dealers
    while($row = odbc_fetch_array($dealers)){
    //break;
        $dealer_code = $row['DEALER_CODE'];
        $dealer_name = $row['DEALER_NAME'];
        $cnic = $row['DEALER_NIC_NO'];
        $dealer_add = $row['DEALER_ADDRESS'];
        $dealer_cell = $row['DEALER_MOBILE_NO'];
        $dealer_email = $row['DEALER_EMAIL'];

        $check_user = "SELECT * FROM axs_web_dealers WHERE DEALER_CODE = $dealer_code";

        $chk_res = mysql_query($check_user) or die("Error: ".mysql_error());

        if(mysql_fetch_array($chk_res) > 0)
            continue;

        else{
                $sql = "INSERT INTO axs_web_dealers (DEALER_CODE, DEALER_NAME, DEALER_NIC_NO, DEALER_ADDRESS, DEALER_MOBILE_NO, DEALER_EMAIL) VALUES ('$dealer_code', '$dealer_name', '$cnic', '$dealer_add', '$dealer_cell', '$dealer_email')";
                mysql_query($sql) or die("Error: ".mysql_error());
        }           

    }

    // insert for axs_web_item
    while($row = odbc_fetch_array($web_item)){
    //break;
        $symbol = $row['ITEM_SYMBOL'];
        $sym_name = addslashes($row['ITEM_NAME']);
        $rate = $row['ITEM_RATE'];
        $high_rate = $row['ITEM_HIGH_RATE'];
        $low_rate = $row['ITEM_LOW_RATE'];
        $vol_qty = $row['ITEM_VOL_QTY'];
        $cdc = $row['CDC'];


        $sql = "INSERT INTO axs_web_item (ITEM_SYMBOL,ITEM_NAME,ITEM_RATE, ITEM_HIGH_RATE, ITEM_LOW_RATE,ITEM_VOL_QTY,CDC) VALUES ('$symbol', '$sym_name', '$rate', '$high_rate', '$low_rate', '$vol_qty', '$cdc')";

        mysql_query($sql) or die("Error: ".mysql_error());
    }

    // insert for axs_web_parties
    while($row = odbc_fetch_array($parties)){
    //break;
        $party_user_code = $row['PARTY_USER_CODE'];//continue;
        $party_name = $row['PARTY_NAME'];
        $agent_code = $row['AGENT_CODE'];
        $party_email = $row['PARTY_EMAIL'];
        $party_add = addslashes($row['PARTY_ADDRESS']);
        $party_cell = $row['PARTY_MOBILE_NO'];
        $party_cnic = $row['PARTY_NIC_NO'];


        $check_user = "SELECT * FROM axs_web_parties WHERE PARTY_USER_CODE = $party_user_code";

        $chk_res = mysql_query($check_user) or die("Error: ".mysql_error());

        if(mysql_fetch_array($chk_res) > 0)
            continue;
        else{
                $sql = "INSERT INTO axs_web_parties (PARTY_USER_CODE, PARTY_NAME, AGENT_CODE, PARTY_EMAIL, PARTY_ADDRESS, PARTY_MOBILE_NO, PARTY_NIC_NO) VALUES ('$party_user_code', '$party_name', '$agent_code', '$party_email', '$party_add', '$party_cell', '$party_cnic')";

                mysql_query($sql) or die("Error: ".mysql_error());

        }
    }


    // insert for axs_web_trans
    while($row = odbc_fetch_array($trans)){
    //break;
        $agent_code = $row['AGENT_CODE'];
        $party_usr_code = $row['PARTY_USER_CODE'];
        $trade_date = $row['TRADE_DATE'];
        $nature = $row['NATURE'];
        $trans_qty= $row['TRANS_QTY'];
        $trans_rate = $row['TRANS_RATE'];
        $trans_item_symbol = $row['TRANS_ITEM_SYMBOL'];
        $set_desc = $row['SET_DESC'];
        $comm = $row['COMM'];
        $trans_amt = $row['TRANS_AMT'];
        $trans_posted = $row['TRANS_POSTED'];
        $trade_desc = $row['TRADE_DESC'];
        $comm_amt = $row['COMM_AMT'];
        $cvt_wht_amt = $row['CVT_WHT_AMT'];
        $fed_amt = $row['FED_AMT'];
        $other_chrg_amt = $row['OTHER_CHRG_AMT'];


        $sql = "INSERT INTO axs_web_trans (AGENT_CODE, PARTY_USER_CODE, TRADE_DATE, NATURE, TRANS_QTY, TRANS_RATE, TRANS_ITEM_SYMBOL, SET_DESC, COMM, TRANS_AMT, TRANS_POSTED, TRADE_DESC, COMM_AMT, CVT_WHT_AMT, FED_AMT, OTHER_CHRG_AMT) VALUES ('$agent_code', '$party_user_code', '$trade_date', '$nature', '$trans_qty', '$trans_rate', '$trans_item_symbol', '$set_desc', '$comm', '$trans_amt', '$trans_posted', '$trade_desc', '$comm_amt', '$cvt_wht_amt', '$fed_amt', '$other_chrg_amt')";

        mysql_query($sql) or die("Error: ".mysql_error());
    }

    // insert for axs_web_voch
    while($row = odbc_fetch_array($voch)){
    //break;
        $voch_no = $row['VOCH_NO'];
        $voch_date = $row['VOCH_DATE'];
        $agent_code = $row['AGENT_CODE'];
        $party_user_code = $row['PARTY_USER_CODE'];
        $narration= $row['NARRATION'];
        $dr_amt = $row['DR_AMOUNT'];
        $cr_amt = $row['CR_AMOUNT'];
        $bal = $row['BALANCE'];
        $index_no = $row['INDX_NO'];
        $check_no = $row['CHEQUE_NO'];
        $effect_code = $row['EFFECT_CODE'];


       $sql = "INSERT INTO axs_web_voch (VOCH_NO, VOCH_DATE, AGENT_CODE, PARTY_USER_CODE, NARRATION,  DR_AMOUNT, CR_AMOUNT, BALANCE, INDX_NO, CHEQUE_NO, EFFECT_CODE)

         VALUES ('$voch_no', '$voch_date', '$agent_code', '$party_user_code', '$narration', '$dr_amt', '$cr_amt', '$bal', '$index_no', '$check_no', '$effect_code')";//exit;

        mysql_query($sql) or die("Error: ".mysql_error());
    }


}
  }

  ?>

<form action="" method="post"
enctype="multipart/form-data">
<label for="file" style="margin-left: 18px;">Filename:</label>
<input type="file" name="file" id="file">
<br>
<input style="margin-left: 78px;" type="submit" name="submit" value="Uplaod DB">
</form>
<?php
}
?>

WINDOWS上的PHP INFO: https://www.dropbox.com/s/4qoqxu87ffwym84/PHP%20INFO%20on%20WINDOWS.png

当我进入Linux时,相同的代码无效... odbc_connect()返回NULL。

LINUX上的PHP INFO: https://www.dropbox.com/s/a3vo6pd5pn1h4ha/PHP%20INFO%20on%20Linux.png

1 个答案:

答案 0 :(得分:0)

我可能会问这个显而易见的问题,但您是否在Linux实例上安装了MS Access的ODBC驱动程序?