Web Hosting Talk







View Full Version : ODBC Problems


UrlGuy
07-25-2005, 04:10 PM
Hi,

I have the program which requires a ODBC connection to input and output data. To get ODBC I whent into Win2k3's start menu, administrative tools and ODBC.. from there I added username, pass, made the db.mdb file and have tested the connection with PHP and it works to connect and query the tables.
But the syntax is a little different for ODBC I believe..
I use this in ODBC to create a table, and it works:

CREATE TABLE users (output VARCHAR(255) NOT NULL);


But I want like with MySQL you can have each new input in the database to be assigned a numeric id which increasing with each new input to the database. To do the same and include a numeric id only in MySQL I would do this:

CREATE TABLE `users` (
`id` INT( 6 ) NOT NULL AUTO_INCREMENT ,
`output` VARCHAR( 255 ) NOT NULL ,
PRIMARY KEY ( `id` )
);


And this works in MySQL and NOT in ODBC...
I have looked around but couldnt find another way to do this:confused:

Hope anyone can help or have any tips or similar.
Grateful for all response.:)

Thanks,
~UrlGuy;)

PerfTuner
07-26-2005, 05:46 PM
MS Access database has slightly different syntax comparing to MySQL.
Try this:

CREATE TABLE 'users' (
'id' COUNTER CONSTRAINT ix_id PRIMARY KEY,
'output' VARCHAR( 255 ) NOT NULL
);

UrlGuy
07-26-2005, 10:31 PM
Thanks for reply.
I get this error when using that code:


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 10
selection failed



Heres my whole file:

<?php

$con = odbc_connect('ren','root','root');
if ($con)
{

$sql="CREATE TABLE 'users' ('id'COUNTER CONSTRAINT ix_id PRIMARY KEY, 'output' VARCHAR( 255 ) NOT NULL )";


$exc = odbc_exec($con,$sql);
}
else
echo "odbc not connected<br>";

if($exc)
{

while(@odbc_fetch_row($exc)){
$output=odbc_result($exc,1);
echo "$output <BR>";
}

}
else
echo "selection failed<br>";

?>


Line 10 is $exc = odbc_exec($con,$sql);


Thanks.

PerfTuner
07-27-2005, 08:19 AM
Try removing quotes also:
$sql="CREATE TABLE users (id COUNTER CONSTRAINT ix_id PRIMARY KEY, output VARCHAR(255) NOT NULL)";