MySQLi extension Flashcards

1
Q

What is the MySQLi extension?

A

MySQLi (MySQL Improved) is a PHP extension that provides an interface for accessing MySQL databases. It offers enhanced features over the older MySQL extension, including support for prepared statements, transactions, and improved security.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How many methods are available to connect to a database using MySQLi?

A

There are three methods to connect to a database using MySQLi:
Method 1 - MySQLi Object-Oriented
Method 2 - MySQLi Procedural
Method 3 - MySQLi with DSN

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Method 1 - MySQLi Object-Oriented

A

$mysqli = new mysqli(“localhost”, “username”, “password”, “database”);

This method creates a new instance of the mysqli class, establishing a connection to the MySQL database using the provided credentials.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Method 2 - MySQLi Procedural

A

$connection = mysqli_connect(“localhost”, “username”, “password”, “database”);

This method uses the mysqli_connect() function to establish a connection to the MySQL database, returning a connection resource.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Method 3 - MySQLi with DSN

A

$dsn = “mysql:host=localhost;dbname=database”;
$username = “username”;
$password = “password”;
$mysqli = new mysqli($dsn, $username, $password);

This method uses a Data Source Name (DSN) to specify the database connection parameters, allowing for a more structured connection string.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly