Page 1 of 1

odbc_exec - returns nothing

Posted: Wed Jul 07, 2010 2:23 pm
by phamot
Hi Everyone:

I am a little new to PHP, so I apologize if this is alot simpler than what I'm making it out to be.

I am attempting to execute some SQL through an ODBC driver, and I seem to have some difficulty in returning the results.

I know my ODBC driver works (I can run the same query through Crystal Reports just fine using the same ODBC driver), but PHP returns no values. I'm starting with a simple script (see below), which ultimately I'd like to put the results into an array for another function. I was able to get this to work on PHP4, but I cannot seem to get this to work on PHP5. I can see on my application logs that I am connecting, but it doesnt seem like the script is executing the query properly.

I get results for $connect and $query, but I get nothing for $result (which according to the PHP documentation, I should get an ODBC result identifier if the SQL command was executed successfully, or FALSE on error. In my case I get absolutely nothing.

Code: Select all

<?php
$connect = odbc_connect('ARSystem', '<username>', '<password>');
$query = "SELECT Change_#, Status FROM CM_Change_Management WHERE Status = 'Draft'";
$result = odbc_exec($connection, $query);
print $connect;
print $query;
print $result;
?>
Any help would be greatly appreciated

Re: odbc_exec - returns nothing

Posted: Wed Jul 07, 2010 2:35 pm
by phamot
I forgot to mention that this is a System DSN ODBC driver too.

Re: odbc_exec - returns nothing

Posted: Wed Jul 07, 2010 2:38 pm
by AbraCadaver
It is returning something:

Code: Select all

var_dump($result);
To get rows of data from that you need to use one of the odbc_fetch_*() functions.

Re: odbc_exec - returns nothing

Posted: Wed Jul 07, 2010 2:44 pm
by phamot
Hi AbraCadaver

Well, that definitely got me farther :D

I just added the var_dump($result); after the odbc_exec per your suggestion, but it returned "NULL". :(

Could it be something with my connection or that I didn't output the results (using odbc_fetch_*)?

Re: odbc_exec - returns nothing

Posted: Wed Jul 07, 2010 2:52 pm
by AbraCadaver
That's strange. I don't use odbc functions but it is very similar to the other PHP DB functions. Try this to see if there is an error:

Code: Select all

$result = odbc_exec($connection,  $query) or die(odbc_errormsg());

Re: odbc_exec - returns nothing

Posted: Wed Jul 07, 2010 3:44 pm
by phamot
Just get a blank screen - its very odd.

I'm starting to wonder if my php install is messed up (I used the manual one).

Re: odbc_exec - returns nothing

Posted: Wed Jul 07, 2010 3:46 pm
by AbraCadaver
Try this:

Code: Select all

$result  = odbc_exec($connection,  $query) or die(odbc_errormsg($connection));

Re: odbc_exec - returns nothing

Posted: Mon Jul 19, 2010 12:37 pm
by phamot
Hi Shawn:

Still no luck - I actually ended up creating a whole new instance using PHP5 and I simply cannot get any results to return at all - here is my PHP Code:

Code: Select all

<?php
$conn = odbc_connect('ARsystem71', '<username>', '<password>');
$query = "SELECT Change_#, Status from CM_Change_Management where Status = 'Draft'";
$result = odbc_exec($conn, $query) or die(odbc_errormsg());
var_dump($num_rows);
print $conn;
print $query;
print $result;
print $num_rows;
?>
The funny thing is that this worked beautifully when I had it in PHP4 - I cant tell if its the driver or what the problem is.

Re: odbc_exec - returns nothing

Posted: Mon Jul 19, 2010 2:29 pm
by phamot
I think I may have this figured out - looks like my driver didn't like PHP5 :?

I finally was able to run a query & give me the # of Rows back - not exactly where I need to be but definitely a start!

Thanks for your help!