how to create connection with database using php

In this tutorial, we will see how to create a connection with a database using PHP for this we require a MySQL database and web development environment using MySQL, Apache and PHP and a simple text editor.


how to create a connection with a database using PHP

The tutorial takes you through a web page using PHP to establish a MySQL connection, connecting to a MySQL table and recovering results and displaying them back on a web page.


This tutorial uses the PHP MySQL command:

mysqli_connect


Firstly we go through:

  • Make connections and select a database.

First up - connecting to a MySQL database:

You need your MySQL server address (if the database is on a server similar to a Web server then it will probably be localhost or 127.0.0.1), username, password, and database name. Create the db.php file and open and close the PHP code with the tag before the HTML, you can then insert the regular HTML. Open the file in the browser and you should not see anything different from the title tag if you get an error check the query of your dbcon.php where the username, password, server name is correct or not.


Connection syntax with a database in PHP:

<--put your servername,username,password(if exists,if not leave it), database name -->
<?php
 $db = mysqli_connect('localhost','username','password','database_name')
 or die('Error connecting to MySQL server.');
?>

<html>
 <head>
 </head>
 <body>
 <h1>Create connection with database in php</h1>
</body>
</html>
how to create connection with database using php how to create connection with database using php Reviewed by Ritesh Vishwakarma on September 02, 2018 Rating: 5

3 comments:

  1. They also have a number of options to accomplish the same results without executing database queries in loop. For instance, the developers can use a robust WordPress plug-in like Query Monitor to view the database queries along with the rows affected by them. plakatų maketavimas

    ReplyDelete
  2. From Philippines Thanks Ritesh :)

    ReplyDelete

Powered by Blogger.