View Database in PHP – With Coding
This blog explains about View Database in PHP – With Coding . It is explained very well below :
In last program, we have created a database “trainee”. Now we are going to see a created database by using given PHP program. You know very well how to connect and create new database, here we have used mysql_fetch_assoc(); to stores all databases in an associative array. The stored databases was selected by using while loop.
Data can be fetched from MySQL tables by executing SQL SELECT statement through PHP function mysql_query. You have several options to fetch data from MySQL.
The most frequently used option is to use function mysql_fetch_array(). This function returns row as an associative array, a numeric array, or both. This function returns FALSE if there are no more rows.
Below is a simple example to fetch records from employee table.
Try out following example to display all the records from employee table.
Lets move into the program,
/* View All Databases */
$host = “localhost”;
$user = “root”;
$pass = “”;
$connect=mysql_connect($host, $user, $pass);
$row=mysql_fetch_assoc($mysql); // stores all databases as an associative array
// The stored databases are
trainee // This is your last created database trainee
In above example the constant MYSQL_ASSOC is used as the second argument to mysql_fetch_array(), so that it returns the row as an associative array. With an associative array you can access the field by using their name instead of using the index.
PHP provides another function called mysql_fetch_assoc() which also returns the row as an associative array.