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条)

报告相同问题?

悬赏问题

  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘