How to establish connection to database using PHP Tutorial

0
53

How to establish connection to database using PHP Tutorial

 

How to establish connection to database using PHP Tutorial

This tutorial is all about How to establish connection to database using PHP Tutorial

 

. In this tutorial you will learn how to connect to the database by using PHP code, connecting to the database will allow you to retrieve some data as well as you can use manipulating basic queries like SELECT, INSERT, UPDATE, DELETE. Please follow all the steps below to complete this tutorial.

Before you can get content out of your MySQL database, you must know how to establish a connection to MySQL from inside a PHP script. To perform basic queries from within MySQL is very easy

The first thing to do is connect to the database. The function to connect to MySQL is called mysqli which I stands for improved. This function returns a resource which is a pointer to the database connection. It’s also called a database handle, and we’ll use it in later functions. Don’t forget to replace your connection details.

 

How to establish connection to database using PHP Tutorial Steps

 

Create a php file by using extension of. php after that

Then copy paste the code below

  1. <? php
  2.  
  3. $server = "yourservername";
  4.  
  5. $user = "root";
  6.  
  7. $pass = "";
  8.  
  9. $database = "your database";
  10.  
  11.  
  12.  
  13.  
  14.  
  15. $conn = new mysqli ($server, $user, $pass, $database);
  16.  
  17.  
  18.  
  19. if($conn->connect_error) {
  20.  
  21. die ("Connection failed");
  22.  
  23. }
  24.  
  25.  
  26.  
  27. ?>

After that you can now manipulate some data in your database by just including this file just like this.

Let say the name of the file is sample.php by calling the connection use include.

 

  1. <? php include ‘sample.php’; ?>

 

Then you’re done. Run your project and see if it works.

 

For questions or any other concerns or thesis/capstone creation with documentation, you can contact me through the following:

E-Mail: ryansalem221996@gmail.com

Facebook: facebook.com/RyyanSalem

Contact No.: +639098911050

Ryan A. Salem

BSIT Graduate, soon to be MIT.

Java Developer / System Developer

Related topic(s) that you make like:

1.) PHP Introduction
2.) PHP echo

 

 

Facebook Comments
(Visited 59 times, 1 visits today)

LEAVE A REPLY

Please enter your comment!
Please enter your name here