DBI mysql question.

Dear MySQL Developers and Enthusiasts,

when I run these lines of code :

my $T_NO = 12569;
use DBI;
my $dbh =
DBI->connect("DBI:mysql:database=carr_search;192.168.0.1",us er,password);

my $q = "CREATE TABLE IF NOT EXISTS CS_? (
ID_NO MEDIUMINT,
NAME VARCHAR(30),
TYPE CHAR(1)
)";
my $sth = $dbh->prepare($q);
$sth->execute($T_NO);

from w/in a program I get:

DBD:mysql::st execute failed: You have an error in
your SQL syntax near '12569 (
ID_NO MEDIUMINT,
NAME VARCHAR(30),
TYP' at line 2 at ./carr_s.pl line 36.

However if I cut and paste the exact same code and
make it it's own program then execute it, it works
perfectly. Can anyone tell me what's happening and how
I can fix it?

Thanks,

Richard

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql [at] m.gmane.org
Richard Reina [ Mi, 16 März 2005 19:10 ] [ ID #698934 ]

Re: DBI mysql question.

Hey,

The placeholders (?) are safely escaped by the DBI library -- your
query that gets submitted to the server actually looks like:

CREATE TABLE IF NOT EXISTS CS_ 12569 (
ID_NO MEDIUMINT,
NAME VARCHAR(30),
TYPE CHAR(1)
)

I think it puts the space in, but it might actually be quoting it.

I would do something like:

$dbh->do(sprintf("CREATE TABLE IF NOT EXISTS CS_%d (
ID_NO MEDIUMINT,
NAME VARCHAR(30),
TYPE CHAR(1)
)", $T_NO));

out.

On Wed, 16 Mar 2005 10:10:39 -0800 (PST), Richard Reina
<richard [at] rushlogistics.com> wrote:
> Dear MySQL Developers and Enthusiasts,
>
> when I run these lines of code :
>
> my $T_NO = 12569;
> use DBI;
> my $dbh =
> DBI->connect("DBI:mysql:database=carr_search;192.168.0.1",us er,password);
>
> my $q = "CREATE TABLE IF NOT EXISTS CS_? (
> ID_NO MEDIUMINT,
> NAME VARCHAR(30),
> TYPE CHAR(1)
> )";
> my $sth = $dbh->prepare($q);
> $sth->execute($T_NO);
>
> from w/in a program I get:
>
> DBD:mysql::st execute failed: You have an error in
> your SQL syntax near '12569 (
> ID_NO MEDIUMINT,
> NAME VARCHAR(30),
> TYP' at line 2 at ./carr_s.pl line 36.
>
> However if I cut and paste the exact same code and
> make it it's own program then execute it, it works
> perfectly. Can anyone tell me what's happening and how
> I can fix it?
>
> Thanks,
>
> Richard
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe: http://lists.mysql.com/mysql?unsub=gary.richardson [at] gmail.com
>
>

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql [at] m.gmane.org
Gary Richardson [ Mi, 16 März 2005 19:28 ] [ ID #698936 ]
Datenbanken » gmane.comp.db.mysql.general » DBI mysql question.

Vorheriges Thema: Adding fields to db table (primary key and other type)
Nächstes Thema: dataKiosk 0.6 released