PHP, MySQL, Drupal, .htaccess, Robots.txt, Phponwebsites: show
show - phponwebsites.com
Showing posts with label show. Show all posts

9 Apr 2014

Get database list in mysql using php

                       You can retrieve databases in your mysql server using php. On mysql server, you can use mysql query in order to get databases in mysql.

Get database list using mysql query:

                                   The following mysql query is used to display database list.

             SHOW DATABASES

It displays database list in mysql as like below:

show databases in mysql using php


Get database list in mysql using php:


                         You can display database list in mysql using php in two ways.
           1.  Display database list using php and mysql query
           2.  Display database list using php and mysql_list_tables()

Display database list using php and mysql:


                                      Now you can find the database list in mysql server using php scripts:


<?php
$link=mysql_connect('localhost','root','')  or die(mysql_error());
$result = mysql_query("SHOW DATABASES")  or die(mysql_error());     
while ($row = mysql_fetch_array($result)) {      
    echo $row[0]."<br>";      
}
?>

                                                                 OR


Display databases in mysql using php and mysql_list_dbs():


                           The php code for display database list:


<?php
$link=mysql_connect('localhost','root','') or die(mysql_error());
$db_list = mysql_list_dbs($link);
while ($row = mysql_fetch_object($db_list))
{
     echo $row->Database . "<br>";
}

?>

Now you'll get output like below:

display databases available in mysql using php

Related Post:

7 Apr 2014

Display tables list in mysql database using php

                      You can display the tables in a mysql database two ways using mysql query.
     1. First you select your mysql database. Then use below mysql query:

                    SHOW TABLES

    2.You can get your tables in mysql database without select database using following mysql query.

                   SHOW TABLES FROM db_name

ex: SHOW TABLES FROM new

Both two ways, you will get output like this:

show tables using mysql_list_tables mysql query

Display table list in database using php:


                            You can display list of tables in database using php in two ways.
           1.  Display table list in database using php and mysql
           2.  Display tables in database using php and mysql_list_tables()

Display table list in database using php and mysql:


                              You can get list of tables in database using mysql query and php. The following php code is used for display list of tables.

<?php
$link=mysql_connect('localhost','root','') or die(mysql_error());
mysql_select_db('new')  or die(mysql_error());
$result=mysql_query("show tables ")  or die(mysql_error());
while ($row = mysql_fetch_row($result)) {
    echo " {$row[0]}<br>";
}
?>

                                        OR

Display tables in mysql database using php and mysql_list_tables():

                             You can also get list of tables in database using mysql_list_tables function in php. The following php code is used for display list of tables.

<?php
error_reporting('E_ALL ^ E_NOTICE');
mysql_connect('localhost','root','') or die(mysql_error());
$rs=mysql_list_tables('new') ;
while($res=mysql_fetch_row($rs))
{
echo $res[0].'<br>';
}
?>

            Now you'll get output like this:

show tables in mysql database using php

Related Post: