Manage Databases on a Server by php

MySQL-related functions.

  • mysql_list_dbs() Used to list the databases on a MySQL server.
  • mysql_num_rows() Returns the number of rows in a result set.
  • mysql_tablename() Despite its name, can extract the name of a table or a database from a result.
The goal of this script is to list all the databases on the local MySQL server.
  1. Open a new file in your text editor and start a PHP block:
    <?
    
  2. Create a variable to hold the result of the mysql_connect() function. Include the @ to suppress warnings, as well as the die() function to cause the script to end and a message to display if the connection fails:
    $connection = @mysql_connect("localhost", "spike", "9sj7En4")
    or die(mysql_error());
    
    
  3. Create a variable to hold the result of the mysql_list_dbs() function. Include the @ to suppress warnings, as well as the die() function to cause the script to end and a message to display if the script can't get the list:
    $dbs = @mysql_list_dbs($connection) or die(mysql_error());
     
    The only argument necessary for the mysql_list_dbs() function is the link identifier for the current connection.

    1. You'll be looping through a result and dynamically populating a bullet list. Start that bullet list outside the loop:
      $db_list = "<ul>";
      
    2. Start a counter. You'll need it for your loop:
      $i = 0;
      
    3. Begin a while loop. This loop will continue for as long as the value of $i is less than the number of rows in the $dbs result value:
      while ($i < mysql_num_rows($dbs)) {
      
    4. Once you're within the while loop, get the name of the database reflected in the current row of the result:
      $db_names[$i] = mysql_tablename($dbs, $i); 
       
      1. The variable $i is replaced by its value, so during the first loop this line would be something like $db_names[0] = mysql_tablename($dbs, 0);
        Counting starts at 0, not 1, so this would reflect the first row in the result. As the counter increments, so does the row number.
      2. Add the current database name to the bullet list:
        $db_list .= "<li>$db_names[$i]";
        
      3. Increment your count before you close the while loop:
        $i++;
        
        
      4. Close the while loop, the bullet list, and your PHP block:
        }
        $db_list .= "</ul>";
        ?>
        
       

     


Related Posts:
  • Php Date or Time Simplest display of date or time is telling your users what time it is. Use the date( ) or strftime( ) strftime( ) says: Wed Oct 20 12:00:00 2004date( ) says: Wed, 20 Oct 2004 12:00:00 -0400 Both strftime( ) and date( )… Read More
  • strtotime php-current time zone strtotime()parsing is always done with the current time zone, unless a different time zone is specified in the string that is parsed:<?phpecho date("H:i T\n", strtotime("09:22")); // shows 09:22 CETecho date("H:i T\n\n", … Read More
  • security to POST-PHP $_POST  POST-method variables. Form field data from regular  POST-method forms.   PHP automatically creates variables for all the data it receives  in an HTTP request. This can include GET data, POST … Read More
  • php-Dynamic Variables Sometimes it is useful to set and use variables dynamically.  Normally, you assign a variable like this:  $var = "hello";   Now let's say you want a variable whose name is the  value of the $var va… Read More
  • Sorting Arrays-PHP PHP supports a variety of ways to sort an array when  I say sort, I am referring to an alphabetical sort if it is a string,  and a numerical sort if it is a number. When sorting an array,  you must k… Read More
  • MySQL with php The basic steps of performing a query, whether using the mysql command-line tool or PHP, are the same:Connect to the database.Select the database to use.Build a SELECT statement.Perform the query.Display the results. Wh… Read More
  • PHP RSS feed script PHP RSS feed script RSS Reader PHP code function get_feed($link) {     $this->load->helper('text');     $last_update = time();     header('Cache-Control: no-cache, must-… Read More
  • What is array Arrays An arrayin PHP is a collection of key/value pairs.  This means that it maps keys or indexes to values. Array indexescan be either integers or strings whereas values can be of any type. Arrays in PHP are implement… Read More
  • Showing the Local Time in Other Time Zones Showing the Local Time in Other Time Zones Sometimes, you want  to show a formatted time in the current time zone and inother time zones as well. The following script shows a full textual date representation for the U.S… Read More
  • Php-Configuration Control Through .htaccess The .htaccessfile is very powerful and can control more than just URL structure. For instance, you can control PHP configuration options using the .htaccessfile. To increase the memory allotted to PHP use this command: php_v… Read More
  • how Installing mod_rewrite localhost If you’ve installed Apache yourself, read on. Because of its  popularity, mod_rewrite is now included with all common  Apache distributions. If desired, you can verify if your Apache installation has the mod_rewr… Read More
  • PHP Jobs interview-Common Section PHP Syntax Variables Operators Arrays If/Then Statements Switch Statements For Loops Foreach Loops While Loops Do While Loops User-Defined Functions Object Oriented Programming with PHP… Read More
  • PHP Expressions An expression is the basic building block of the language.  Anything with a value can be thought of as an expression.  Examples include: 5 5+5 $a $a==5 sqrt(9) By combining many of these basic expressions, you… Read More
  • Create Login page php-Php code  Create Login page php <?php             session_start();             $host="localhost"; // Host name &n… Read More
  • Building Dynamic Images-PHP You want to create an image based on a existing image template and dynamic data typically text). For instance, you want to create a hit counter. Load the template image, find the correct position to properly cente… Read More