mysql_select_db not working

Discussion in 'PHP' started by bonecone, Oct 31, 2011.

  1. #1
    I have a page, index.php, that includes a function.php file at the beginning which contains the following two functions

    
    function g_db_connect($server = DB_SERVER, $username = DB_SERVER_USERNAME, $password = DB_SERVER_PASSWORD, $database = DB_DATABASE, $link = 'db_link') {
       global $$link;
    
       if(USE_PCONNECT == 'true') {
          $$link = mysql_pconnect($server, $username, $password);
       } else {
          $$link = mysql_connect($server, $username, $password);
       }
    
       if ($$link) mysql_select_db($database);
    
       return $$link;
    }
    
    function g_db_query($query, $link = 'db_link') {
       global $$link;
    
       if(defined('STORE_DB_TRANSACTIONS') && (STORE_DB_TRANSACTIONS == 'true')) {
          error_log('QUERY ' . $query . "\n", 3, STORE_PAGE_PARSE_TIME_LOG);
       }
    
       $result = mysql_query($query, $$link) or g_db_error($query, mysql_errno(), mysql_error());
    
       if(defined('STORE_DB_TRANSACTIONS') && (STORE_DB_TRANSACTIONS == 'true')) {
          $result_error = mysql_error();
          error_log('RESULT ' . $result . ' ' . $result_error . "\n", 3, STORE_PAGE_PARSE_TIME_LOG);
       }
    
       return $result;
    }
    
    Code (markup):
    The page itself contains the code

    
    g_db_connect() or die('Could not connect to the Database');
    
    $manu_sql    = 'SELECT * FROM '.TABLE_PREFIX.'manu';
    $manu_query  = g_db_query($manu_sql);
    
    Code (markup):
    But when I try to access the page I get the error message 1046 - No database selected
    Why isn't it selecting the database? I've verified that the constants contain the values they are supposed to contain.
     
    bonecone, Oct 31, 2011 IP
  2. kellyphong

    kellyphong Peon

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Add following line;

    define( 'DB_DATABASE', 'YOUR DATABASE NAME HERE');
    Code (markup):
    (replace YOUR DATABASE NAME HERE with your actual mysql database name)

    _before_ calling following line;


    g_db_connect() or die('Could not connect to the Database');
    Code (markup):
     
    kellyphong, Oct 31, 2011 IP
  3. dustalelaki

    dustalelaki Well-Known Member

    Messages:
    94
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    111
    #3
    great kelly
     
    dustalelaki, Nov 1, 2011 IP
  4. David Lemarier

    David Lemarier Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I have do my custom db.class.php check this out ;)

     
    David Lemarier, Nov 8, 2011 IP