Hot Posts

7 Easy Steps to Create Database Application in PHP


WampServer, a popular web development environment for Windows, provides a simple and easy yet powerful platform for creating dynamic web applications. PhpMyAdmin is one of the key components of WampServer. It is a web-based interface for managing MySQL databases. 

In this comprehensive guide, we will walk through the step-by-step process of creating a database using phpMyAdmin within the WampServer environment.

Prerequisites

  • You must have WampServer installed on your Windows machine. 
  • You must have Login details to login to phpMyAdmin.
  • You must have basic knowledge about MySQL commands.

7 Easy Steps To Create Database Application in PHP

There are easy steps to create database application in PHP. You just have to use inbuilt functions provided by PHP.

The steps are


1) Establish connection with MySQL Server

The function that helps to establish the connection is mysql_connect().

Provide appropriate values especially server name, username and password.


2) Select the Database

The function that helps to select the database from the list of database on Mysql Server is mysql_select_db().

Provide appropriate values especially database name, and connection variable name.


3) Prepare Query

Query is the SQL statement that you want to execute on table of the particular database.

It can be SELECT, INSERT, UPDATE or DELETE.


4) Execute Query

The function that helps to execute the query prepared in above step is mysql_query().

Provide appropriate values especially query variable name and connection variable name.


5) Fetch the Data

This step is required when SELECT query is to be executed.

The function that helps to fetch the data are a) mysql_fetch_row() and 2) mysql_fetch_array().

Provide appropriate values especially result-set variable name. 


6) Display the Data

Once the data is fetched, then you can display the data on the screen.

The function that helps to display the data are a) echo() and 2) print().


7) Close the Connection

Finally, the last step is to close the connection.

This step releases the resources of the server.

The function that helps to close the connection is mysql_close().

Provide appropriate values especially connection variable name.
Apart from these functions you can also use inbuilt functions like mysql_error(), mysql_num_rows(), mysql_affected_rows()


Example

<html>

<head><title> Steps to create database application in PHP </title></head>

<body>

<?php

    $conn = mysql_connect("localhost","root");
   
    mysql_select_db("student_info",$conn);

    $sql = "select * from student";

    $result = mysql_query($sql,$conn);

    $row = mysql_fetch_row($result);

    $totalrows = mysql_num_rows($result);

    echo "total rows fetched are : ".$totalrows;
   
    echo "<h1>rows are : </h1><br/>";

    while ($row =  mysql_fetch_row($result))
    {
       
        echo "rollno :".$row[0]."<br/>" ;
       
        echo "student Name : ".$row[1]."<br/>";
       
        echo "Phone : " .$row[2]."<br/>";
       
        echo "mobile : ".$row[3]."<br/>";
       
        echo "<br/>";
    }
   
mysql_close($conn);

?>

</body>

</html>

Conclusion

Creating a database in phpMyAdmin with WampServer is a important step in developing PHP-MySQL based websites. Whether you're building a simple or a complex website, understanding how to manage databases is very vital.

In this guide, we covered the step-by-step process of creating a database using phpMyAdmin within the WampServer environment. From accessing phpMyAdmin to creating a new database and exploring additional options, you now have the foundational knowledge that will help you to start working with databases in your web projects.

Post a Comment

0 Comments