English
Tamil Nadu Board of Secondary EducationHSC Science Class 12

Explain in details types of MySQL connection method in PHP? - Computer Applications

Advertisements
Advertisements

Question

Explain in details types of MySQL connection method in PHP?

Answer in Brief

Solution

  1. Database Connections:
    Before accessing MySQL Database, connect to Database Server machine via PHP scripting language using Mysqli_connect( ) Function.
    Syntax:

    mysqli_connect(“Server Name”,“User Name”,“Password”,“DB Name”);

    This function requires four parameters to connect to the database server. Database Server name, Database username, password and Database Name.

  2. Managing Database Connections:
    The below code snippet describes managing database connection methods and features.
    <?php
    $servemame = “localhost”;
    $usemame = “username”;
    $password = “password”;
    SDB_name = “SchoolDB”;
    // Create connection
    $conn = mysqli_connect($servemame, Susemame, Spassword,$DB_name);
    // Check connection
    if(!$conn){
    die(“Connection failed: “ . mysqli_connect_error( ));
    }
    echo “Connected successfully”;
    ?>

    In the above code snippet, three variables are used to connect to the Database server. They are

    1. $servemame → Database Server Server IP address
    2. $username → Database Server User Name
    3. $password → Database Server Password
    4. $DBName → Database Name

      The mysqli_connect function uses these variables and connect Database server from PHP scripting. If connection gets fail, output will be printed with MySQL error code. Otherwise connection is a success.

shaalaa.com
MYSQL Function in PHP
  Is there an error in this question or solution?
Chapter 9: Connecting PHP and MYSQL - Evaluation - PART – IV [Page 132]

APPEARS IN

Samacheer Kalvi Computer Applications [English] Class 12 TN Board
Chapter 9 Connecting PHP and MYSQL
Evaluation - PART – IV | Q 2. | Page 132
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×