What is the error in getting an info from MSSQL? Enclosed herewith: an error message and source of the program

[Fri Feb 22 12:54:15 2008] [error] [client 132.64.4.16] PHP Warning: odbc_exec() [function.odbc-exec]: SQL error: [unixODBC][FreeTDS][SQL Server]Could not find stored procedure 'SHOW'., SQL state 37000 in SQLExecDirect in /srv/www/htdocs/hu/Proj1/test.php on line 9
[Fri Feb 22 12:54:15 2008] [error] [client 132.64.4.16] PHP Warning: odbc_fetch_row(): supplied argument is not a valid ODBC result resource in /srv/www/htdocs/hu/Proj1/test.php on line 10
[Fri Feb 22 12:54:15 2008] [error] [client 132.64.4.16] PHP Warning: odbc_free_result(): supplied argument is not a valid ODBC result resource in /srv/www/htdocs/hu/Proj1/test.php on line 14

The test source program is:

--- begin odbctest.php---
<?
// connect to DSN MSSQL with a user and password
$connect = odbc_connect("DSNNAME", "user", "passwd") or die
("couldn't connect");
print "connection ok";
odbc_exec($connect, "use SwitchCenterDB");
print "SwitchCenterDB ok";
$result = odbc_exec($connect, "SHOW TABLES");
while(odbc_fetch_row($result)){
print(odbc_result($result, "CompanyName") .
' ' . odbc_result($result, "ContactName") . "\n");
}
odbc_free_result($result);
odbc_close($connect);
?>
--- end odbctest.php --

same here

R's picture

we encountered same problem:
[Fri Feb 22 12:54:15 2008] [error] [client 132.64.4.16] PHP Warning: odbc_fetch_row(): supplied argument is not a valid ODBC result resource in /srv/www/htdocs/hu/Proj1/test.php on line 10

as

Warning: odbc_fetch_row(): 9 is not a valid ODBC result resource in /var/www/localhost/htdocs/customer.microprecision.com/gage.php on line 182

and my code:

<?
odbc_close($conn1);
// List Events For This Instrument
$conn2=odbc_connect($db_host,$db_user,$db_pass);
$sql2="SELECT * FROM events where events.company = '$custid' and ".
"gage_sn = '$cal' and ".
"(event_type like '%cal%' or event_type = 'Repair' or event_type = 'Op-Check')";
//echo $sql2;
//echo $cal;
$rs2=odbc_exec($conn2,$sql2);
if (!$rs2)
{exit("Error in SQL");}
?>

Event Type
Documents
Cal Date
Calibration Result

<?
odbc_fetch_row($rs2, 0);
while (odbc_fetch_row($rs2)) <------line 182------>
{
$etype=trim(odbc_result($rs2,"event_type"));
$enum=odbc_result($rs2,"event_num");
$edate=odbc_result($rs2,"event_date");
$edate = date("M-j-Y", strtotime($edate));
$eresult=trim(odbc_result($rs2,"event_result"));
?>

i wonder how you solve this one? i wish that you can help me. please send me an email --> ran.september@gmail.com thanks!

Bad SQL

paul.bohme's picture

The first error is the real one: You're feeding it something it doesn't know how to deal with. A bit of googling comes up with 'show tables' being a MySQL-ism - not something SQL Server is going to understand.

The other errors come from not checking the result set before trying to use it. ;-)

I am by no means an expert

Mike Roberts's picture

I am by no means an expert on your topic but something did catch my eye. The line in your sample code:
print(odbc_result($result, "CompanyName") .
' ' . odbc_result($result, "ContactName") . "\n");

appears to me to have an extra ) between "\n" and the ;

Just a guess but if that is really in the code that could be all or part of the problem.

Happy hunting!

Mike Roberts is a bewildered Linux Journal Reader Advisory Panelist.

Webcast
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers

Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.

Learn More

Sponsored by AMD

White Paper
Red Hat White Paper: Using an Open Source Framework to Catch the Bad Guy

Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6

Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.

Learn more about catching the bad guy in this free white paper.

Learn More

Sponsored by DLT Solutions