My SQL


How to connect MySQL database using PHP

Coding Issue for android php java html-css and javascript

Let’s start with PHP and MySQL connection process. The first thing to do is connect MySQL database using PHP, and try to get information on database tables on the page. The function to connect to MySQL is called mysqli_connect (). This function returns a connection to pop for the database MySQL connection, that’s called a database handling.

There are few important MySQL functions for the PHP MySQL commands:

1. mysqli_connect: The most important mysqli_connect() function opens a new connection to the MySQL server.

2. mysqli_query: The mysqli_query() function performs a query against the database.

3. mysqli_num_rows: The mysqli_num_rows() function returns the number of rows in a result set.

4. mysqli_fetch_array: It’s Returns an array that corresponds to the fetched row or NULL if there are no more rows for the result set represented by the result parameter.

5. mysqli_close: The mysqli_close() function closes a previously opened database connection.

Must read this:

Explode string by the last occurrence and get the first part

Let’s start with first function of php for connect MySQL database using PHP:

mysqli_connect :

After connection successfully created need to hit a query where data is stored with table:

mysqli_query :

When the query is executed we need to how much data received on page :

mysqli_num_rows :

Now we just need to go through all the rows of that query which we need mysqli_fetch_array which stores the rows in an array, we can get the data of this array usning while loop :

mysqli_fetch_array :

Just because of this function we can fetch the all rows of the query result.

Finally we need to close the database connection using mysqli_close :

mysqli_colse :

Result :

Published by Amit Pandey

Professional Android app Developer, Full Stack Web Developer, Blogger, Entrepreneur And Founder of Coding Issue. I am always trying to learn new things or new possible ways to do things.

Did you find this page helpful?

X

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*

*