473,387 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Problems with ODBC_exec

20
I am connecting to a Microsoft Access via ODBC and I am connecting successfully. When I try to query a table using the SQL statement illustrated in my code I get no results even for values that are in the table. If I echo my query statement $q and put it in MS office IDE it gives me some results can anyone help?
[php]
$conn=ODBC_connect('Msc', 'user', 'password');
if ($conn)
{
$q = "
SELECT * FROM tblUsers WHERE UserName='$user' AND Pasword='$pword'";
$r = odbc_exec($conn,$q);
if (odbc_num_rows($r) == 1) {
return TRUE;
} else {
return FALSE;
}[/php]
Mar 10 '08 #1
8 8683
ronverdonk
4,258 Expert 4TB
Please enclose any code within the proper code tags. See the Posting Guidelines on how to do that.

MODERATOR
Mar 10 '08 #2
ronverdonk
4,258 Expert 4TB
When your quere results in an error, you do not catch it. So make your statement[php]$r = odbc_exec($conn,$q) or die("Error :".odbc_error_msg());[/php]Then you will see the error in the select statement.

Ronald
Mar 10 '08 #3
Garudzo
20
When your quere results in an error, you do not catch it. So make your statement[php]$r = odbc_exec($conn,$q) or die("Error :".odbc_error_msg());[/php]Then you will see the error in the select statement.

Ronald
It is not giving an error. Infact it was giving an error when I used double quotes to enclose my variables. I corrected that and put single quotes then its not giving any error and it does not give the correct result
Mar 10 '08 #4
code green
1,726 Expert 1GB
it does not give the correct result
It does give the correct result but you don't understand it
Try some debugging [PHP]$conn = ODBC_connect('Msc', 'user', 'password') or die(odbc_errormsg());
$q = "SELECT * FROM tblUsers WHERE UserName='$user'
AND Pasword='$pword'";
echo $sql;
if($r = odbc_exec($conn,$q))
echo odbc_num_rows($r);
else
return FALSE;
[/PHP] Is the field name correct?
Expand|Select|Wrap|Line Numbers
  1.  Pasword 
Mar 10 '08 #5
ronverdonk
4,258 Expert 4TB
I saw that also, but then the die() on the SELECT should have given the error. And according to OP it gives no error.

Ronald
Mar 10 '08 #6
code green
1,726 Expert 1GB
Hi ronverdonk
I am more worried about this [PHP]if (odbc_num_rows($r) == 1) {
return TRUE;
} else {
return FALSE;[/PHP] Too defintive. That's why I suggested [PHP]echo $sql;
if($r = odbc_exec($conn,$q))
echo odbc_num_rows($r);
else
return FALSE;[/PHP]
Mar 10 '08 #7
Garudzo
20
Hi ronverdonk
I am more worried about this [PHP]if (odbc_num_rows($r) == 1) {
return TRUE;
} else {
return FALSE;[/PHP] Too defintive. That's why I suggested [PHP]echo $sql;
if($r = odbc_exec($conn,$q))
echo odbc_num_rows($r);
else
return FALSE;[/PHP]
The echo [PHP]odbc_num_rows($r) [/PHP] gives -1
Mar 11 '08 #8
ronverdonk
4,258 Expert 4TB
Let's stick with the standard PHP documentation for this moment. It states explicitly:
odbc_num_rows() will return the number of rows in an ODBC result. This function will return -1 on error. For INSERT, UPDATE and DELETE statements odbc_num_rows() returns the number of rows affected. For a SELECT clause this can be the number of rows available.

Note: Using odbc_num_rows() to determine the number of rows available after a SELECT will return -1 with many drivers.
So your driver could be the cause. But there is a work-around, from the same doc:
This function (odbc_num_rows) returns -1 when ODBCing to MS SQL and making it hard to get the number of rows in the returned recordset.

Two workarounds:
1. When you just need to verify that any rows returned from your query you can use select count(*) as cnt from table and then just get $row['cnt']
2. When you need to actually loop through the records this function returns number of rows in the recordset if and only if you include ORDER BY clause in your query statement.

That sounds a bit annoying but thats the work around when dealing with MS SQL odbc driver I guess.
I must assume it is a driver error, since the code sounds fine and you do not get an error at the select. So try this work around and see if that works. I don't think it is a solution, but that way you can at least see that your odbc works on that table.

Ronald
Mar 11 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: mk | last post by:
Hi to all, I want to execte some query using odbc_exec, but i receive the following error both using odbc_exec or odbc_prepare. Connection is successful but the other functions will fail. PHP...
7
by: Karin Jensen | last post by:
Hi I am running a PHP program that connects to an Access 2000 database via ODBC: $results = odbc_exec($connection_id, $sql_select); Is it possible to sort the contents of $results? I wish to...
14
by: Wescotte | last post by:
I have an application that uses several file formats for similar data. So I've created various php files for each format containing the same functions which produce the same end result. Now I...
0
by: u4yk | last post by:
I posted this on php.dev, but I'd give you guys a shot. I'm running PHP 5.1.1 on a Linux box, and when I try to send an MS SQL database via ODBC, I get the following error: PHP Warning: ...
1
by: Mitch | last post by:
I'm moving a script from MySQL to MS Access (yuck). Anyway, when I do an insert or select with an email address as a field value in odbc_exec, ODBC barfs on me. Is there some special quoting...
1
by: stonicus | last post by:
// Relevant parts of my DB class (from include file) class db_connection { function __construct() { $this->con = odbc_connect('ShippingData','name','pass'); } private...
2
by: JoeNinja | last post by:
Im failing to update the an MS ACcess. I will appreciate Your advice. I get the error below Warning: odbc_exec() : SQL error: Too few parameters. Expected 1., SQL state 07001 in SQLExecDirect in...
0
by: CislaghiAndrea | last post by:
Pc configuration : XAMPP per Windows Version 1.5.1 PHP Version 5.1.1 IBM DB2 ODBC DRIVER 8.01.14 the query ==> Database DB2 IBM 8.1 on Z9 with ZOS 1.9 odbc_exec($db,"SELECT * FROM...
0
by: imusion | last post by:
Hi, I have 2 servers each running AIX and both have a DB2 database setup on them. I'm building a news management application and in our setup we need to have a staging and production setup. So...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.