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.