Page 1 of 1

Noob question: '[| |]' in MySQL queries

Posted: Tue Aug 02, 2011 9:21 am
by RCA86
Hi guys, this is a total noob question, but it's been eating away at my brain for the past few months. :banghead:

In a MySQL query, there's this code: ' ... [|PREFIX|]products ...'. Now I know exactly what this does, it inserts the prefix for the table, as this is globally configurable, but I don't know if it's PHP, MySQL, or where/how you can define this.

Put me out of my misery? :D

Re: Noob question: '[| |]' in MySQL queries

Posted: Tue Aug 02, 2011 12:00 pm
by twinedev
that would be handled by the php program to do the replacement, most likely a custom defined function. ex:

Code: Select all

// The following would most likely get set in a config/settings file for the app.
$strTablePrefix = 'mytable_';

function runQuery($sql) {
    return mysql_query(str_replace('[|PREFIX|]',$strTablePrefix,$sql);
}

$rsProduct = runQuery('SELECT * FROM [|PREFIX|]products WHERE ProductID = 3');
The main purpose would be to just make the code more readable and easier to type since you don't have to close quote (or use variables withing double quotes).

The above could have just been written as:

Code: Select all

// The following would most likely get set in a config/settings file for the app.
$strTablePrefix = 'mytable_';

$rsProduct = mysql_query('SELECT * FROM '.$strTablePrefix.'products WHERE ProductID = 3');

Re: Noob question: '[| |]' in MySQL queries

Posted: Wed Aug 03, 2011 4:28 am
by RCA86
Ah, so it's not any kind of special syntax after all. Makes sense!

Thanks!