Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2005

    PHP: ODBC Query problem


    I'm now trying ODBC for my server, but this is really new to me, although it looks kinda similar to MySQL.

    This is the current script I have digged up until now:

    PHP Code:


    if (
    "odbc connected<br>";
    $sql =  "CREATE TABLE info ( 
    output VARCHAR( 255 ) NOT NULL , 
    user VARCHAR( 15 ) NOT NULL , 
    PRIMARY KEY ( `id` ) 

    $exc odbc_exec($con,$sql);  
    "odbc not connected<br>";
    "selection completed<br>";
    $row odbc_fetch_row($exc) )
    "no workie<br>";
    It gets connected, but its something wrong with the query. This should work with MySQL which I'm getting used to so I can't really find whats wrong.

    Heres the error I get:

    odbc connected
    Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC Microsoft Access Driver] Syntax error in CREATE TABLE statement., SQL state 37000 in SQLExecDirect in W:\www\odbc\odbc.php on line 16
    selection failed
    Ok it says odbc connected, so it connected OK.

    If I run this query: SELECT * FROM nothing
    it will say 'nothing' doesnt exist. So this kinda works OK. But the above query doesnt seem to work for some reason.

    Basicly all I need to do is setup a table.
    With MySQL thats pretty simple by using that above code, or by using the commandline. But for ODBC I didnt find any commandline so I cant see which tables are already there.. neither do I know how to create ones.

    Thanks for all help!!

  2. #2
    Join Date
    Feb 2005
    Ok, now I solved that, and couldnt edit my above post and neither do I want to start a new so here's my further problems:

    The syntax for ODBC are a little different from MySQL I think, atleast the one for creating a table, so hope anyone can give me a helping hand here.

    This works, but only create a column called output in the table temp:
    $sql = "CREATE TABLE temp (output VARCHAR(255) NOT NULL);";

    But this doesnt assign each new I add there a uniqe ID, which increases.
    For that I use the below code in MySQL but this doesnt work with ODBC. Hope anyone can help me debug/fix this code:

    $sql = "CREATE TABLE temp (output VARCHAR(255) NOT NULL), id INT(6) NOT NULL AUTO_INCREMENT), PRIMARY KEY (id));";

    ^Its supposed to create 1 table and 2 fields.
    The table is named 'temp'
    First field is named 'output' and can be 255 chars long.
    Second field is 'id', which is supposed to increase every time I add one, and increase itself by one. Therefore the AUTO_INCREMENT.

    Thanks for all help.. greatly apprecciated!!!
    Thanks again!

Posting Permissions

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