Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Feb 2005
    Posts
    663
    Thanks
    5
    Thanked 14 Times in 14 Posts

    sql prefix not working

    I'm changing the names of my table to work with a prefix, and in my config file I have the following:
    PHP Code:
    $mysql_prefix 'prefix_'
    And in my code, I have query's such as
    PHP Code:
    $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.

  • #2
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    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:
    PHP Code:
    global $mysql_prefix
    and let us know how it turns out.

    OR...

    Define the table prefix as a constant:
    PHP Code:
    define'MYSQL_PREFIX''prefix_' ); 
    PHP Code:
    $sql1 "SELECT * FROM " MYSQL_PREFIX "game_info"
    It will then work regardless of scope.
    Last edited by kbluhm; 02-20-2008 at 09:37 PM.

  • #3
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    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

  • #4
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    I personally would define a constant as Kbluhm suggested.
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.

  • #5
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by StupidRalph View Post
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •