View Full Version : sql prefix not working

02-20-2008, 10:27 PM
I'm changing the names of my table to work with a prefix, and in my config file I have the following:

$mysql_prefix = 'prefix_';

And in my code, I have query's such as

$sql1 = "SELECT * FROM " . $mysql_prefix . "game_info";

However, on some of my pages/scripts, the prefix is not working. I'm not sure, but I believe it may be scripts that are being called in using require(mypage.php)

I wish i could provide more info, but I'm not sure even what else to mention or why the prefix works on some pages/scripts and not others.

02-20-2008, 10:34 PM
Is the $sql1 variable being declared within a function?

If so, add this line at the very top of the function, within the first curly brace:

global $mysql_prefix;
and let us know how it turns out.


Define the table prefix as a constant:

define( 'MYSQL_PREFIX', 'prefix_' );

$sql1 = "SELECT * FROM " . MYSQL_PREFIX . "game_info";
It will then work regardless of scope.

02-20-2008, 10:34 PM
the query is ok, from my point of view.

get a page where did not work and post code to see what's happend.

best regards

02-20-2008, 10:42 PM
I personally would define a constant as Kbluhm suggested.

02-20-2008, 11:05 PM
I personally would define a constant as Kbluhm suggested.
I'm agreed, that could be the problem and the solution.

I don't see kbluhm post until now, :). The timestamp seems to be the same, kbluhm post few seconds earlier. :)

best regards