Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 2 of 2
  1. #1
    Senior Member hagen's Avatar
    Join Date
    Aug 2005
    Posts
    408
    Member #
    10882
    Liked
    1 times
    Hiya took a while for me to sort this but found the best way to use multiple databases seems to be as follows (it selects one of two databases using the resource $link_cms and $link_beach):

    Note: mysql_connect(bla....., true). The true forces a new link resource for PHP 4.1 onwards...



    PHP Code:
    <?php

    $mysql_username     
    "aaaaaa";       
    $mysql_password     "******";          
    $mysql_servername   "localhost";            
    $mysql_databasename "qqqqqq";
    $link_cms mysql_connect($mysql_servername,$mysql_username,$mysql_password,true);
    if (!
    $link_cms) die("Couldn't connect to MySQL 1");
    mysql_select_db($mysql_databasename,$link_cms);



    $mysql_username     "bbbbbb";       
    $mysql_password     "zzzzzz";          
    $mysql_servername   "localhost";            
    $mysql_databasename "rrrrr";
    $link_beach mysql_connect($mysql_servername,$mysql_username,$mysql_password,true);
    if (!
    $link_beach) die("Couldn't connect to MySQL 2");
    mysql_select_db($mysql_databasename,$link_beach);



    $result mysql_query("SELECT * FROM huts",$link_beach) or die("SELECT Error 1".mysql_error());

    $result mysql_query("SELECT id FROM jos_menu",$link_cms) or die("SELECT Error 2".mysql_error());


    ?>
    Hagen Rose: hagen(at)jxwd(dot)co(dot)uk
    JX Web Development, Bournemouth, Dorset...JXWD.co.uk

  2.  

  3. #2
    Senior Member hagen's Avatar
    Join Date
    Aug 2005
    Posts
    408
    Member #
    10882
    Liked
    1 times
    oh and also if you want use resources inside functions you need to declare them as global...

    IE

    PHP Code:
    function functionName() {
      global 
    $link_cms;

     .. 
    code...


    :-)
    Hagen Rose: hagen(at)jxwd(dot)co(dot)uk
    JX Web Development, Bournemouth, Dorset...JXWD.co.uk


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 10:53 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com