Page 198 - CITS - Computer Software Application -TT
P. 198

COMPUTER SOFTWARE APPLICATION - CITS



            PHP MySql connection-Get connected with
            mysqli_connect


           PHP MySQL Connection
           Introduction:
           Establishing a connection between PHP and MySQL is fundamental in building dynamic web applications. MySQL
           is a popular relational database management system, and PHP provides robust functions, particularly through
           the `mysqli` extension, to interact seamlessly with MySQL databases. This chapter will cover the process of
           connecting to MySQL using `mysqli_connect` and performing basic MySQL queries and operations.
           Connecting to MySQL using mysqli_connect:
           Explanation:
           `mysqli_connect`  is  a  PHP  function  that  establishes  a  connection  to  a  MySQL  database.  It  requires  specific
           parameters such as the MySQL server address, username, password, and the target database name.
           Example:





























           In this example, we attempt to connect to a MySQL database on the local server with the given credentials. If the
           connection fails, an error message is displayed; otherwise, a success message is echoed.
           Basic MySQL queries and operations
           A list of commonly used MySQL queries to create database, use database, create table, insert record, update
           record, delete record, select record, truncate table and drop table are given below.
           PHP MySQL Create Table
           A database table has its own unique name and consists of columns and rows.
           Create a MySQL Table Using MySQLi
           The CREATE TABLE statement is used to create a table in MySQL.
           We will create a table named “MyGuests”, with five columns: “id”, “firstname”, “lastname”, “email” and “reg_date”:















                                                           185

                             CITS : IT&ITES - Computer  Software Application - Lesson 47 - 62
   193   194   195   196   197   198   199   200   201   202   203