Gossamer Forum
Home : General : Databases and SQL :

Adding Table Prefix to mysql call - perl

Quote Reply
Adding Table Prefix to mysql call - perl
Hi All

Here's my situation. I'd like to add a table prefix to all the mysql calls in one of my perl scripts. I'm gonna put the following in the config file, and then make the adjustments:

Quote:
$dbprefix = 'fred_';

The problem for me is how to add it to the calls in the scripts. For example, is adding $dbprefix as simple as the following, or should I have some quotes or something in there:

Code:
$statement = 'SELECT * FROM
$dbprefixusers WHERE username = ?';

Thanks a bunch Smile

------------------------------------------

Last edited by:

DogTags: Feb 7, 2003, 6:36 AM
Quote Reply
Re: [DogTags] Adding Table Prefix to mysql call - perl In reply to
Should it look like the following....just add a dot:

$statement = 'SELECT * FROM
$dbprefix.users WHERE username = ?';

------------------------------------------
Quote Reply
Re: [DogTags] Adding Table Prefix to mysql call - perl In reply to
You'll need either:

$statement = 'SELECT * FROM ' . $dbprefix . 'users WHERE username = ?';

or:

$statement = "SELECT * FROM ${dbprefix}users WHERE username = ?";

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Adding Table Prefix to mysql call - perl In reply to
Hey, Boss!

Thanks!! Smile

------------------------------------------