Database Connectivity and Session Handling
Database Connectivity and Session Handling
09CE1503
1
PHP – MySQL database
connectivity
Key Components of MySQL Database Connectivity
1. Connection: Establishing a link between the application and the
MySQL server.
2. Authentication: Using credentials (username and password) to
authenticate the connection.
3. Query Execution: Sending SQL commands to the database to perform
various operations.
4. Result Handling: Processing the data returned from the database.
5. Error Handling: Managing any errors that occur during the database
operations.
6. Connection Closure: Properly closing the connection once operations
are completed.
PHP – MySQL database
Connectivity using MySQLi
● MySQLi (MySQL Improved) is an extension provided by PHP
to interact with MySQL databases.
● It offers both procedural and object-oriented approaches.
● You can create a connection using the mysqli_connect
function in procedural style or the mysqli class in object-
oriented style.
PHP – MySQL database
connectivity
● MySQL database connectivity refers to the process of
establishing a connection between a software application and a
MySQL database.
● This connection allows the application to interact with the
database, enabling it to perform various operations such as
querying, inserting, updating, and deleting data.
● In the context of PHP, MySQL database connectivity involves
using extensions like MySQLi or PDO to facilitate
communication with the MySQL server.
1. Establishing a Connection
Procedural Style:
1. Establishing a Connection
Object-Oriented Style:
2. Selecting a Database
Object-Oriented Style:
3. Executing Queries
Object-Oriented Style:
4. Handling Results
Object-Oriented Style:
5. Closing the Connection
Procedural Style:
Object-Oriented Style:
PHP – MySQL database
Connectivity using PDO
● Using PDO (PHP Data Objects) for MySQL database connectivity provides a
robust and flexible way to interact with a MySQL database.
● PDO supports various database systems and offers features like prepared
statements, which enhance security and performance.
2. Using Cookies:
● Cookies can be used to store session identifiers or small
amounts of session data on the client-side.
Different ways to handle session
data