Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
1.8k views
in Connecting PHP and MYSQL by (54.8k points)
closed by

Discuss in detail about MySQL functions with example?

1 Answer

+1 vote
by (49.1k points)
selected by
 
Best answer

MySQL Function in PHP:

In PHP Scripting language many functions are available for MySQL Database connectivity and executing SQL queries. MySQLi is extension in PHP scripting language which gives access to the MYSQL database. MySQLi extension was introduced version 5.0.0.

The MySQLi extension contains the following important functions which are related to MySQL database connectivity and management.

1. Mysqli_connect( ) Function

2. Mysqli_close( ) Function

3. mysqli_select_db( ) Function

4. mysqli_affected_rows( ) Function

5. mysqli_connect_error( ) Function

6. mysqli_fetch_assoc( ) Function

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 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”;

$DB_name = “School_DB”;

// Create connection

$conn = mysqli_connect($servemame, Susemame, $password,$DB_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 success.

3. Performing Queries:

The main goal of MySQL and PHP connectivity is to retrieve and manipulate the data from MySQL database server. The SQL query statements are helping with PHP MySQL extension to achieve the objective of MySQL and PHP connection, “mysqliquery” is a function, helps to execute the SQL query statements in PHP scripting language.

Syntax:

mysqli_query(“Connection Object” , ’’SQL Query”)

Example:

$con=mysqli_connect(“localhost” , “my_user” , “my_pass word” , “Student_DB “); $sql= ”SELECT

student_name,student_age FROM 

student”;mysqli_query($con,$sql);

4. Closing Connection:

mysqli_close( ) Function is used to close an existing opened database connection between PHP scripting and MySQL Database Server.

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...