doudilin1225 2013-06-11 15:10
浏览 84
已采纳

你如何从PHP连接到oracle db

I am trying to connec to oracle table from php. I have odbc configured and tested that it works. I have the following php file that I created to test the connection but I get

This is the code:

<html>
<body>

<?php
$conn=odbc_connect('<dsn name>','<username>','<password>');
if (!$conn) {exit("Connection Failed: " . $conn);}
$sql="SELECT T."Node" from <table name> T";
$rs=odbc_exec($conn,$sql);
if (!$rs) {exit("Error in SQL");}
echo "<table><tr>";
echo "<th>Companyname</th>";
echo "<th>Contactname</th></tr>";
while (odbc_fetch_row($rs))
{
    $compname=odbc_result($rs,"CompanyName");
    $conname=odbc_result($rs,"ContactName");
    echo "<tr><td>$compname</td>";
    echo "<td>$conname</td></tr>";
}
odbc_close($conn);
echo "</table>";
?>

</body>
</html> 

My version :

C:\PHP>php --version
PHP 5.3.26 (cli) (built: Jun  5 2013 19:16:29)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies

I configured error on on the php.ini file and I am getting this error:

Parse error: syntax error, unexpected T_STRING in C:\inetpub\wwwroot\test.php on line 8

it is complaining about the sql line. it does not like this T."Node" ( the double quotes). Is it possible to escape the double quotes within the sql line in php. How would I address this?

  • 写回答

3条回答 默认 最新

  • ds355020 2013-06-11 15:28
    关注
    sql="SELECT T."Node" from <table name> T";
    

    must be

    sql="SELECT T" . $node. " from <table name> T";
    

    if $node is a var,

    sql="SELECT T.\"Node\" from <table name> T";
    

    otherwise to escape the quotes.

    You might want to use some editor with syntax and error highlighting, e.g. netbeans, eclipse, notepad++...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用