Tutorial How to Write PHP Database Connection



The common problem dealing with people who want to do programming is how to write PHP database. The main procedure to perform this task is using MySQL. When it comes to programming, MySQL is an important part. It is mostly used for installing the server. Therefore establishing database connection will require this open source database. Aside from MySQL, popular open source databases that are frequently used are including Apache and PHP. However, in this article, we are going to limit the discussion on how to establish open PHP MySQL database connection. The tutorial will talk about the popular method to write down the program. 

How to Establish open PHP MySQL Database Connection

Before digging into the how to do it properly, you might ask why we need to use MySQL instead of other open databases. There are several good reasons for it. Portability benefit is the main reason this program is highly recommended. It is able to run in any operating system without any problems. Most importantly, it is multi-user program. It means that more than one user are able to operate the same program at the same time. The speed of MySQL on handling numerous queries is also incredible. The various types of data that can be accommodated by MySQL allow us to be creative.

1.        Connecting to the MySQL program
In order to establish connection to the MySQL program, you will need the server address of this open database. At this phase, you ideally already determining the open database server that you want to use. Keep in mind that it is not the same as localhost. Once you already obtain the server address, you can create the PHP file afterwards. To create it, you will need to begin the html code with simple tags. The command of MySQL that is needed for this html coding is the mysqli_connect. If you do not perform it correctly, a notification will suddenly pop up on the screen. Figure out where you make the mistake to continue on the next step.
2.        Execute the query
Since the query is already completed, it is time to execute the query. The query should consist of any fields collected from the table. On this stage, you can see the monitor that displays the contents PHP MySQL create table. Instead of single MySQL command, it takes to in order to complete the program. Those commands are mysqli_query and mysqli_fetch_array. Friendly tip to perform it faster is by checking the table contents.
3.        Close the connection
The last part you need to do when writing PHP database connection is closing the connection. Why you need to close the connection that is complicated to establish? It is important to secure the open database connection. Make sure to close your tags properly as well. Closing the connection is the highly recommended to make you get used to select individual records on the coding. The MySQL command used to close the connection is mysqly_close. Note that you should not leave the connection open at all time.
SHARE

About andy

I made this blog just to make about the science that I learned during the study, if there is something wrong please comment below, and do not forget to share, thank you.

    Blogger Comment
    Facebook Comment

0 komentar:

Posting Komentar