0

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?

user1471980
  • 10,127
  • 48
  • 136
  • 235
  • 2
    A 500 status code (or a blank page) normally means that your script is throwing an error but you haven't configured PHP to display error messages. That's something you need to fix before you go further; it's impossible to code without the aid of error messages. Here's a [brief explanation](http://stackoverflow.com/a/5680885/13508). – Álvaro González Jun 11 '13 at 15:12
  • You might well find the error message in the error logs for your server however. – Orbling Jun 11 '13 at 15:13
  • 1
    Check the server error log. it'll have more details about the 500 error. Plus, command-line php information is rarely useful for diagnosing web-based problems. It's entirely possible to have multiple versions of PHP installed, and web v.s. cli can have different configurations on top of that. – Marc B Jun 11 '13 at 15:14
  • @Alvar G.Vicorio, I have updated the orinal post. – user1471980 Jun 11 '13 at 15:18
  • Right, you have a syntax error, nothing related to ODBC or Oracle. Have a look at the [strings](http://es1.php.net/manual/en/language.types.string.php) section in the PHP manual. There're also IDEs with PHP syntax checking. – Álvaro González Jun 11 '13 at 15:21
  • And, before you ask, `` is not a valid identifier in Oracle. Why the `<>`?
    – Álvaro González Jun 11 '13 at 15:23
  • Álvaro, it's common to anonymize code before posting on SO. – 000 Jun 11 '13 at 15:42

3 Answers3

2
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++...

Zsolt Szilagyi
  • 4,741
  • 4
  • 28
  • 44
0

You can get rid of the quotes around the table. Those are not needed.

$sql="SELECT T.Node from <table name> T";
Andy
  • 49,085
  • 60
  • 166
  • 233
0

There is a syntax error here:

$sql="SELECT T."Node" from T";

use literal string (single quotes) if you want to use quotes inside the string:

$sql='SELECT T."Node" from T';

immulatin
  • 2,118
  • 1
  • 12
  • 13