QODBC / SQL查询/ php混合集成

时间:2014-03-18 11:55:29

标签: php sql odbc

我正在开发一个基于PHP Web的门户网站,供客户使用QODBC连接与他们的QuickBooks数据库进行交互。这种联系很强大并且有效,我在那里没有问题;但是,到目前为止,我无法回应QB内任何表格中的任何数据。

我在下面用来连接或运行查询的方法有问题吗?

我应该使用不同类型的连接字符串吗?

谢谢你们。

<?php
set_time_limit(120);

#Connect to a System DSN "QuickBooks Data" with no user or password
$oConnect = odbc_connect("QRemote Server","","");




#Set the SQL Statement
$sSQL = "SELECT TOP 50 ListID, FullName, CompanyName FROM Customer";

#Perform the query
$oResult = odbc_exec($oConnect, $sSQL);


//Test connection to DB
    if($oConnect == false){
        echo "<span style='color:ff0000;'>Failure to connect</span>";
    } else {
        echo "<span style='color:00ff00;'>Connected to DB</span>";  
    }
    echo "<br />";

//Test if query is working
    echo "<br />";
    echo "If this equals <i>-1</i>, it isn't working";
    echo "<br />";
    echo "Value:".odbc_num_rows($oResult);
    echo "<br />";
    if (odbc_num_rows($oResult)=="-1"){
        echo "<b><span style='color:ff0000;'>fail</span></b>";
    } else {
        echo "<b><span style='color:00ff00;'>pass</span></b>";
    }
    echo "<br />";
    echo "<br />";
    echo "<br />";

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
    <title>QODBC PHP Script To Display SQL Results</title>
</head>
<body topmargin="3" leftmargin="3" marginheight="0" marginwidth="0" bgcolor="#ffffff" link="#000066" vlink="#000000" alink="#0000ff" text="#000000">
<table border="0" border="0" bordercolor="black" cellpadding="0" cellspacing="0">
    <tr>
        <td>
            <table border="2" bordercolor="black" bgcolor="white" cellpadding="5" cellspacing="0">
                <thead>
                    <caption align="top">QODBC PHP Script To Display SQL Results</caption>
                    <tr>
                        <th>Row</th>
                        <?php
                            $lFldCnt = 0;
                            $lFieldCount = odbc_num_fields($oResult);
                            while ($lFldCnt < $lFieldCount) {
                                $lFldCnt++;
                                    $sFieldName = odbc_field_name($oResult, $lFldCnt);
                                echo("                        <th>$sFieldName</th>\n");
                            }
                        ?>
                    </tr>
                </thead>
                <tbody>
<?php
$lRecCnt = 0;
#Fetch the data from the database
while(odbc_fetch_row($oResult)) {
    $lRecCnt++;
    print("                    <tr>\n");
    print("                        <td>$lRecCnt</td>\n");
    $lFldCnt = 0;
    $lFieldCount = odbc_num_fields($oResult);
    while ($lFldCnt < $lFieldCount) {
        $lFldCnt++;
        $sFieldValue = trim(odbc_result($oResult, $lFldCnt));
        If ($sFieldValue == "") {
            print("                        <td> </td>\n");
        }
        else {
            print("                        <td valign=\"Top\">$sFieldValue</td>\n");
        }
    }
    print("                    </tr>\n");
}
#Close the connection
odbc_close($oConnect);
?>
                </tbody>
                <tfoot>
<?php
    echo "<br />";
    echo "<br />";
print("                    <caption align=\"bottom\">Results of: $sSQL</caption>");
?>
                </tfoot>
            </table>
        </td>
    </tr>
</table>
</body>
</html>

----编辑日志---- 编辑(2014年3月19日上午7:14 AEST) - 添加了我以前忘记的$ oResult

1 个答案:

答案 0 :(得分:0)

我建议转介

PHP - http://qodbc.com/links/2892&amp; http://qodbc.com/links/2623

远程访问QuickBooks数据 - http://qodbc.com/links/2517