+ Reply to Thread
Results 1 to 5 of 5

Thread: PHP mysql_list_dbs

  1. #1
    darkpunkcalob is offline x10Hosting Member darkpunkcalob is an unknown quantity at this point
    Join Date
    Jul 2009
    Posts
    22

    PHP mysql_list_dbs

    I am having an issue with this script, when vist the page, it just loads forever.

    What am i doing wrong?

    PHP Code:
    <?php
    $host 
    "localhost";
    $user "user1234";
    $password "pass1234";

    $connection mysql_connect ($host$user$password) or die ('DB connection failed because: ' mysql_error());
    $list mysql_list_dbs($connection) or die ('DB list failed because: ' mysql_error());
    while (
    $row mysql_fetch_object($list)) {
         echo 
    $row;
         echo 
    "<br />";
    }
    ?>

  2. #2
    hoj469066 is offline x10Hosting Member hoj469066 is an unknown quantity at this point
    Join Date
    Aug 2010
    Location
    Denmark
    Posts
    3

    Re: PHP mysql_list_dbs

    Hi,

    Change this line: echo $row;
    to this:
    echo $row->Database;


  3. #3
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: PHP mysql_list_dbs

    Quote Originally Posted by darkpunkcalob View Post
    I am having an issue with this script, when vist the page, it just loads forever.
    Are you sure it takes forever to load, as opposed to generating no visible content?

    Don't use die when outputting HTML. Rather than the very outdated mysql driver, use PDO. Here's what it would look like

    PHP Code:
    <?php
    try {
      
    // LocalDB isn't a standard class; keep reading for more.
      
    $db LocalDB::connect();
      
    ?>
      <ul>
        <?php foreach ($db->query('SHOW DATABASES') as $dbName): ?>
          <li><?php echo $dbName[0]; ?></li>
        <?php endforeach; ?>
      </ul>
      <?php
    } catch (PDOException $exc) {
       
    /* only admins should be shown raw MySQL error. Of course,
          only admins should see the list of database names.
        */
       
    echo $exc->getMessage();
    }
    ?>
    If any value in the statement varies (which is much of the time), you'd use PDO::prepare rather than PDO::query.

    For example implementations of LocalDB, see (e.g.) "Re: Display all that would be secret while Mysql is broken", "Re: [PHP] MySQL and PHP".
    Last edited by misson; 11-25-2010 at 01:20 AM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  4. #4
    darkpunkcalob is offline x10Hosting Member darkpunkcalob is an unknown quantity at this point
    Join Date
    Jul 2009
    Posts
    22

    Re: PHP mysql_list_dbs

    I am sure.

    At any rate, I have eliminated the need for this script.

    Thanks to all who helped.

  5. #5
    pixelboy_95's Avatar
    pixelboy_95 is offline x10Hosting Member pixelboy_95 is an unknown quantity at this point
    Join Date
    Nov 2010
    Posts
    4

    Cool Re: PHP mysql_list_dbs

    I once made a nice script for that. When you press a button it shows the databases with javascript

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers