#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Posts
    60
    Rep Power
    15
    Hi,
    I am having difficulties choosing a dynamic database. when I do the following line, it does not work:
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>$result = mysql_db_query($client_db, $query);[/code]
    however, this line does:
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>$result = mysql_db_query("databasename1", $query);[/code]

    How can I dynamically point to a database using something like $client_db=databasename1?
    (client_db does echo correctly when tested)

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre><?
    //echo "$client_db";
    $client_db='"databasename1"';
    $appno='10438';
    mysql_connect("localhost", "uname", "passwd");
    $query = "select appno, entity from base where appno='$appno'";
    $result = mysql_db_query($client_db, $query);
    //$result = mysql_db_query("databasename1", $query);
    if ($result) {
    while ($r = mysql_fetch_array($result)) {
    $appno = $r["appno"];
    $entity = $r["entity"];

    echo "$appno";
    echo "$entity";
    }
    }
    ?>[/code]

    [This message has been edited by aarongb (edited June 08, 2000).]
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    63
    Rep Power
    15
    I tried it an it works fine when you declare the database variable without single quotes as below...

    $client_db="databasename1";

    I don't really know about how other programmers work but genearally I only use single quotes within select statements but never in php code.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Posts
    60
    Rep Power
    15
    Thanx,
    I'm feeling all egg-faced. In the actual code, I had a require() pointing to a file with a different dbname (which was correct all along). Doh!

Similar Threads

  1. Selecting from more than two tables
    By JonnyThunder in forum MySQL Help
    Replies: 9
    Last Post: February 4th, 2004, 07:24 AM
  2. Replies: 2
    Last Post: January 28th, 2004, 08:07 AM
  3. selecting distring records across multiple tables
    By kubicon in forum MySQL Help
    Replies: 3
    Last Post: January 9th, 2004, 06:41 PM
  4. selecting common cols in multiple tables
    By phprook in forum MySQL Help
    Replies: 8
    Last Post: December 10th, 2003, 02:48 PM
  5. Replies: 1
    Last Post: September 27th, 2003, 11:03 AM

IMN logo majestic logo threadwatch logo seochat tools logo