mysqli Flashcards

1
Q

What MySQL version accessibility can be accessed by mysqli?

A

4.1 and above.

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

What is the “dual interface” feature of the mysqli extension?

A

It supports the procedural and object-oriented programming interface.

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

Is there a performance difference between the mysql and mysqli extensions?

A

No.

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

Can you switch between procedural and object-oriented interfaces with mysqli?

A

Yes, but it’s not recommended.

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

Can you open a TCP/IP connection using the hostname ‘localhost’?

A

No, ‘localhost’ is bound to the use of Unix domain sockets. You must use 127.0.0.1 instead.

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

What happens when using mysqli, and a connection parameter is omitted?

A

mysqli will attempt to use the default values that are set in the PHP configuration file. If that doesn’t work, then it may default to the library built-in values.

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

What is the mysqli default host value?

A

A Unix socket connection on localhost. If socket is unset or empty, and a Unix socket connection is requested, then a connection to the default socket on /tmp/mysql.sock is attempted. If not, it will default to post 3306.

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

Can connection options be set after a network connection is established?

A

No.

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

For setting a connection option, what three steps are performed?

A
  1. Creating a connection handle with mysqli_init().
  2. Setting the requested options using mysqli_options().
  3. Establishing the network connection with mysqli_real_connect().
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How does connection pooling work?

A

By default, mysqli uses persistent database connections, which are a special kind of pooled connection. By default, every database connection opened by a script is either explicitly closed by the user during runtime, or released automatically at the end of the script. Persistent connections, however, are put into a pool for later reuse, if a connection to the same server using the same username, password, socket, port and default database is opened.

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

Can a pooled connection be used by one or more scripts subsequently?

A

Yes.

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

When does mysqli open a new connection?

A

When an unused persistent connection for a given combination of host, username, password, socket, port, and default database can not be found in the connection pool.

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

What PHP directive can be used to enable and disable the use of persistent mysql connections?

A

myqsli.allow_persistent

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

How can you limit the total number of persistent mysql connections allowed by a script?

A

With the PHP directive mysqli.max_links.

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

How can you limit the maximum number of persistent mysql connections allowed by a PHP process?

A

With the PHP directive mysqli.max_persistent.

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

Are artifacts from previous usages of the same connection visible in persistent connections?

A

No. The persistent connection appears to the user as if it was just opened. Before a persistent connection is reused, the mysqli extension implicitly calls mysqli_change_user() to reset the state.

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

Calling mysqli_query() is identical to calling…

A

…mysqli_real_query() followed by mysqli_store_result().

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

mysqli_query() combines statement execution and…

A

…result set buffering.

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

When should unbuffered mysql result sets be used?

A

When client memory is a short resource, and freeing server resources as early as possible to keep server load low is important.

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

With the text protocol, the MySQL server converts all data of result sets into ______ before sending.

A

strings

This conversion is done regardless of the SQL result set column data type.

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

For integer and float columns, how can you convert them back to PHP numbers?

A

Set the MYSQLI_OPT_INT_AND_FLOAT_NATIVE connection option, if using mysqlnd library.

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

What is another name for a prepared statement?

A

Parameterized statement.

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

The MySQL server supports using anonymous, positional placeholder with…

A

?

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

What is the basic workflow of prepared statements?

A
  1. At the prepare stage, a statement template is sent to the database server. The server performs a syntax check and initializes server internal resources for later use. This only happens on the first invocation of a prepared statement.
  2. During the execute stage, the client binds parameter values and sends them to the server. The server creates a statement from the statement template and the bound values to execute it using the previously-created internal resources.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

When should prepared statements be closed?

A

Immediately after use. If not done explicitly, the statement will be closed when the statement handle is freed by PHP.

26
Q

When is a prepared statement less efficient than a non-prepared statement.

A

When it’s run only once.

27
Q

What is the difference between the data transfer protocols for prepared and non-prepared statements?

A

For prepared statements, results are not serialized into strings before sending, and the client libraries do not receive strings only. Instead, they will receive binary data and try to convert the values into appropriate PHP data types.

28
Q

What are the two ways to retrieve results from prepared statements?

A

Binding output variables, or requesting a mysqli_result object.

29
Q

What two rules cover output variable binding from mysql results?

A
  1. Output variables must be bound after statement execution.

2. One variable must be bound for every column of the statements result set.

30
Q

Prepared statements return _____ result sets by default.

A

unbuffered

31
Q

What function can you use to buffer the results of a prepared statement?

A

mysqli_stmt_store_result()

32
Q

Instead of using bound results, how can you return a buffered result set through the mysqli_result interface?

A

Use mysqli_stmt_get_result().

33
Q

What protections do bound variables offer for SQL queries?

A

Bound variables are sent to the server separately from the query, and thus cannot interfere with it.

34
Q

Do bound parameters need to be escaped?

A

No, as they are never substituted into the query string directly.

35
Q

What MySQL statement is used to execute a stored procedure?

A

CALL

36
Q

Stored procedures can have ___, ____, and ____ parameters, depending on the MySQL version.

A

IN, INOUT, and OUT

37
Q

How are the values of INOUT/OUT parameters accessed?

A

Using session variables.

38
Q

What can stored procedures return?

A

Result sets.

39
Q

How can result sets from a stored procedure be returned?

A

Not using mysqli_query. Instead, use mysqli_real_query() or mysqli_multi_query().

40
Q

What happens when you fail to fetch all result sets returned by a stored procedure?

A

It causes an error.

41
Q

What’s the advantage of having multiple MySQL statements in one statement string?

A

It reduces client-server round trips.

42
Q

How are multi queries executed?

A

With mysql_multi_query(). The individual result sets are separated by semicolons.

43
Q

With multi queries, can you have statements that do return result sets and statements that do not return result sets in one multiple statement?

A

Yes.

44
Q

Are multi queries with prepared statements supported?

A

No.

45
Q

What is the default storage engine?

A

InnoDB since MySQL 5.5.

46
Q

How should you do transactions in MySQL?

A

Through the API.

47
Q

How can you access MySQL result set metadata?

A

All of it is accessible through the mysqli interface, using mysqli_result.

48
Q

With what versions of MySQL is the mysqli extension compatible?

A

It’s designed to work with 4.1.13 or newer, or 5.0.7 or newer.

49
Q

How do you set MYSQL_OPT_READ_TIMEOUT through an API call or runtime configuration setting?

A

You can’t.

50
Q

Does mysqli offer a separate function for opening persistent connections?

A

No.

51
Q

How do you open a persistent connection with mysqli?

A

By prepending ‘p:’ to the hostname when connecting.

52
Q

What cleanup procedures does mysqli perform on persistent connections?

A
  • rollback active transactions
  • close and drop temp tables
  • unlock tables
  • reset session variables
  • close prepared statements
  • close handler
  • release locks acquired with GET_LOCK()
53
Q

How do you switch off the automatic connection cleanup procedures that mysqli performs with persistent connections?

A

Compile with MYSQLI_NO_CHANGE_USER_ON_PCONNECT defined.

54
Q

Does mysqli support persistent connections with MySQL Client Library?

A

Yes, with both MySQL Client Library and MySQL Native Driver.

55
Q

What does the mysql_stmt class represent?

A

A prepared MySQL statement.

56
Q

What does the mysqli_result class represent?

A

The result set obtained from a query against the database.

57
Q

What can you use mysqli_driver for?

A

Stopping and starting the embedded server, and configuring internal error reporting functions.

58
Q

What does the mysqli_warning class represent?

A

A MySQL warning.

59
Q

What is the mysqli exception handling class, and what does it extend?

A

mysqli_sql_exception extends RuntimeException

60
Q

Why use MySQL Native Driver instead of MySQL Client Library?

A
  • It’s under PHP license, not MySQL license.
  • You do not need MySQL installed in order to build PHP or run PHP database applications.
  • It’s more efficient.
  • Improved persistent connections.
  • mysqli_fetch_all()
  • performance statistics calls: mysqli_get_cache_stats(), mysqli_get_client_stats(), mysqli_get_connection_stats()
61
Q

How can you track memory usage with MySQL Native Driver?

A

memory_get_usage()

62
Q

As of PHP 5.4.0, what is the default MySQL driver for all extensions?

A

MySQL Native Driver