ODBC Errors In Query

This is a discussion on ODBC Errors In Query within the PHP Language forums, part of the PHP Programming Forums category; I normally use MySQL with PHP, but I'm delving into connecting to Access with ODBC (for a database that ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-23-2004
Steve
 
Posts: n/a
Default ODBC Errors In Query

I normally use MySQL with PHP, but I'm delving into connecting to Access
with ODBC (for a database that I already have set up at work), and I'm
running into a couple of errors. I'm just trying to do a simple query
with two columns - one a name (VARCHAR), and one an integer column.

First, if I add an ORDER BY clause, so the query looks like this:

$sql = "select tblScores.FullName, sum(tblScores.Points) as TotalPoints
from tblScores WHERE Division='MO'";
$sql = $sql." GROUP BY tblScores.FullName";
$sql= $sql." ORDER BY TotalPoints desc";

I get an ODBC error that says:

"odbc_exec(): SQL error: [Microsoft][ODBC Microsoft Access Driver] Too
few parameters. Expected 1., SQL state 07001 in SQLExecDirect in
c:\program files\apache group\apache\htdocs\odbc\file.php on line 15"

However, if I remove the ORDER BY clause, the query runs (although the
data isn't sorted the way I would like). I have a feeling it might be
something in my SQL, but I can't see it.

Later, I did discover that if I use

ORDER BY sum(tblScores.Points)

instead of the alias (TotalPoints) the query works fine. That seems odd
to me, because everything I've read is that you should be able to use an
alias in an ORDER BY clause. Why would it behave that way when
connecting via ODBC and not for MySQL?

The second thing I'm noticing is that even though I'm using an integer
field, there is a decimal on the end of each number (i.e. 25.0 instead
of 25). When I run the same query using MySQL, there is no decimal
point, which is as it should be.

Can anyone explain why I am getting these errors?

Thanks.

Steve
Reply With Quote
  #2 (permalink)  
Old 10-24-2004
Tim Roberts
 
Posts: n/a
Default Re: ODBC Errors In Query

Steve <racquetballer@hotmail.com> wrote:

>I normally use MySQL with PHP, but I'm delving into connecting to Access
>with ODBC (for a database that I already have set up at work), and I'm
>running into a couple of errors. I'm just trying to do a simple query
>with two columns - one a name (VARCHAR), and one an integer column.
>
>First, if I add an ORDER BY clause, so the query looks like this:
>
>$sql = "select tblScores.FullName, sum(tblScores.Points) as TotalPoints
>from tblScores WHERE Division='MO'";
>$sql = $sql." GROUP BY tblScores.FullName";
>$sql

= $sql." ORDER BY TotalPoints desc";
>
>I get an ODBC error that says:
>
>"odbc_exec(): SQL error: [Microsoft][ODBC Microsoft Access Driver] Too
>few parameters. Expected 1., SQL state 07001 in SQLExecDirect in
>c:\program files\apache group\apache\htdocs\odbc\file.php on line 15"
>
>However, if I remove the ORDER BY clause, the query runs (although the
>data isn't sorted the way I would like). I have a feeling it might be
>something in my SQL, but I can't see it.
>
>Later, I did discover that if I use
>
>ORDER BY sum(tblScores.Points)
>
>instead of the alias (TotalPoints) the query works fine. That seems odd
>to me, because everything I've read is that you should be able to use an
>alias in an ORDER BY clause. Why would it behave that way when
>connecting via ODBC and not for MySQL?


If the alias works in MySQL, it is an extension. Standard SQL requires
that you use the full text of the field.

>The second thing I'm noticing is that even though I'm using an integer
>field, there is a decimal on the end of each number (i.e. 25.0 instead
>of 25). When I run the same query using MySQL, there is no decimal
>point, which is as it should be.


What is the type of the Access field, exactly? Is it Currency?

>Can anyone explain why I am getting these errors?


In short, because Access is a piece of crap. You would do better with
SQLite.
--
- Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
Reply With Quote
  #3 (permalink)  
Old 10-24-2004
Steve
 
Posts: n/a
Default Re: ODBC Errors In Query

Tim Roberts wrote:

>>The second thing I'm noticing is that even though I'm using an integer
>>field, there is a decimal on the end of each number (i.e. 25.0 instead
>>of 25). When I run the same query using MySQL, there is no decimal
>>point, which is as it should be.

>
>
> What is the type of the Access field, exactly? Is it Currency?


No it is Integer. That's why I'm confused as to why there would be a
decimal place.

>
>
>>Can anyone explain why I am getting these errors?

>
>
> In short, because Access is a piece of crap. You would do better with
> SQLite.


This was set up a few years ago, and changing it isn't an option right now.

Thanks.

Steve
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 08:24 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0