SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    May 2005
    Location
    London, ON
    Posts
    360
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question SQL + ODBC --> Why the error?

    Hello,

    I am using an ODBC connection to access data stored in an access file. I can connect to the database fine, and have run a few successful queries. However, the large query I need to run is causing an error. Here is my code:

    PHP Code:
    /* QUERY TABLE FOR REQUESTED DATA
    * This will query the database and return all information needed to create the announcement
    * - $connect is from dbConnect.php 
    */
    $query "SELECT sponsor_pgm_comp.CMP_GUIDELINE_URL, sponsor_detail.SPNSR_NAME, sponsor_pgm.PGM_NAME, sponsor_pgm_comp.CMP_NAME, sponsor_pgm_comp.CMP_AWARD_RANGE, sponsor_pgm_comp.CMP_OPEN_DT, sponsor_pgm_comp.CMP_INTERNAL_DT, sponsor_pgm_comp.CMP_DEAN_DATE, sponsor_pgm_comp.CMP_AGENCY_DT, sponsor_pgm.PGM_DESCRIPTION, sponsor_pgm_comp.CMP_DETAIL, sponsor_pgm_comp.CMP_ADMIN_INFO, sponsor_pgm_comp.CMP_INT_CONTACT_NM, sponsor_pgm.PGM_CONTACT, sponsor_address.* FROM sponsor_detail, sponsor_pgm, sponsor_pgm_comp, sponsor_address WHERE sponsor_detail.SPNSR_ID = sponsor_pgm.SPNSR_ID AND sponsor_pgm.PGM_ID = sponsor_pgm_comp.PGM_ID ORDER BY sponsor_detail.SPNSR_NAME ASC";

    echo 
    "Query: ".$query;
    // perform the query 
    $result odbc_exec($connect$query);

    // fetch the data from the database 
    while (odbc_fetch_row($result)) { 
        
    $name odbc_result($result"SPNSR_NAME"); 
        
    $pgm_type odbc_result($result"SPNSR_PGM_TYPE"); 
        print(
    "Name: $name Type: $pgm_type <br />"); 
        }

    //disconnect from the database
    require("../includes/dbDisconnect.php"); 
    The error I get is with the odbc_exec() funtion. The error message is:

    Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 2., SQL state 07001 in SQLExecDirect in C:\blahblah\findSponsor.php on line 14

    Any ideas?
    Ryan Price
    Subscribe to my blog for regular tips and tricks

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,263
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    run your query directly in access, i.e. outside of php

    that way you will discover what the real error message is

    by the way, your joins seem incomplete

    do you realize that each combination of sponsor_detail, sponsor_pgm, sponsor_pgm_comp is joined with all addresses in the sponsor_address table
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •