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.

Webinar
One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems

As Linux continues to play an ever increasing role in corporate data centers and institutions, ensuring the integrity and protection of these systems must be a priority. With 60% of the world's websites and an increasing share of organization's mission-critical workloads running on Linux, failing to stop malware and other advanced threats on Linux can increasingly impact an organization's reputation and bottom line.

Learn More

Sponsored by Bit9

Webinar
Linux Backup and Recovery Webinar

Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.

In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.

Learn More

Sponsored by Storix