PHP ODBC SQL 连接

发布于 2024-11-26 19:23:17 字数 1238 浏览 1 评论 0原文

一家公司最近要求我使用一些 PHP 来桥接他们拥有的多个数据库。虽然他们的大多数新数据库都是 MySQL,但他们有一个 PROGRESS 数据库。一切都很顺利,直到我遇到了一个小错误。

该代码运行良好,除了 j.JobNum 返回以下错误:

Field j.JobNum not found in LOCATION

如果我删除最后一个 JOIN,它工作正常。对于任何重叠字段也会发生同样的情况。如果行重叠,则无法输出。

$table_name = "Customer";
$fields = 'j.JobNum, Name, City, State, Zip';

$conn = odbc_connect($dsn, $username, $password, SQL_CUR_USE_ODBC);

$field_array = explode(', ', $fields);

$sql = "SELECT TOP 50 ".$fields." FROM PUB.JobProd j LEFT JOIN PUB.BookOrd b ON j.OrderNum=b.OrderNum LEFT JOIN PUB.Customer c ON b.CustNum=c.CustNum LEFT JOIN PUB.JobHead jh ON j.JobNum=jh.JobNum";
    echo '<table>';
    echo '<tr><td>JobNum</td><td>Name</td><td>City</td><td>State</td><td>Zip</td></tr>';
    $rs = odbc_exec($conn,$sql) or die('Select failed!');
        while(odbc_fetch_row($rs)){
            echo '<tr>';
            foreach($field_array as $key=>$field){
                echo "<td>".odbc_result($rs, $field)."</td>";
            }
            echo '</tr>';
        }
    echo '</table>';      
odbc_close($conn);

有解决办法吗?我的代码有问题吗?

A company recently asked me to bridge the multiple databases they have with some PHP. While most of their new databases are MySQL, they have one that is a PROGRESS database. Everything was going good until I ran into a slight error.

The code runs great except that j.JobNum returns the following error:

Field j.JobNum not found in LOCATION

If I remove the last JOIN it works fine. The same happens for any overlapping fields. If rows overlap they cant be outputted.

$table_name = "Customer";
$fields = 'j.JobNum, Name, City, State, Zip';

$conn = odbc_connect($dsn, $username, $password, SQL_CUR_USE_ODBC);

$field_array = explode(', ', $fields);

$sql = "SELECT TOP 50 ".$fields." FROM PUB.JobProd j LEFT JOIN PUB.BookOrd b ON j.OrderNum=b.OrderNum LEFT JOIN PUB.Customer c ON b.CustNum=c.CustNum LEFT JOIN PUB.JobHead jh ON j.JobNum=jh.JobNum";
    echo '<table>';
    echo '<tr><td>JobNum</td><td>Name</td><td>City</td><td>State</td><td>Zip</td></tr>';
    $rs = odbc_exec($conn,$sql) or die('Select failed!');
        while(odbc_fetch_row($rs)){
            echo '<tr>';
            foreach($field_array as $key=>$field){
                echo "<td>".odbc_result($rs, $field)."</td>";
            }
            echo '</tr>';
        }
    echo '</table>';      
odbc_close($conn);

Is there a solution for this? Is something wrong with my code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我早已燃尽 2024-12-03 19:23:17

尝试这样做

$sql = "SELECT TOP 50 ".$fields." FROM PUB.JobProd AS j LEFT JOIN PUB.BookOrd AS b 
ON j.OrderNum=b.OrderNum LEFT JOIN PUB.Customer AS c 
ON b.CustNum=c.CustNum LEFT JOIN PUB.JobHead AS jh 
ON j.JobNum=jh.JobNum";

Try to do this

$sql = "SELECT TOP 50 ".$fields." FROM PUB.JobProd AS j LEFT JOIN PUB.BookOrd AS b 
ON j.OrderNum=b.OrderNum LEFT JOIN PUB.Customer AS c 
ON b.CustNum=c.CustNum LEFT JOIN PUB.JobHead AS jh 
ON j.JobNum=jh.JobNum";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文