Advertisements
Advertisements
Question
Explain in details types of MySQL connection method in PHP?
Solution
-
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.
- 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
- $servemame → Database Server Server IP address
- $username → Database Server User Name
- $password → Database Server Password
- $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.
APPEARS IN
RELATED QUESTIONS
Which is the not a correct MySQL Function in PHP?
How many parameter are required for MYSQLi connect function in PHP?
How many parameter are required for MYSQLI Close function in PHP?
Which version of PHP supports MySQLi fuctions?
What is MySQLi function?
What are the types MySQLi function available PHP?
Give few examples of MySQLi Queries.
What is Connection string?
Write the Syntax for MySQLi Queries.
Discuss in detail about MySQL functions with example.