PHP ODBC SQL 连接
一家公司最近要求我使用一些 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试这样做
Try to do this