PHP: mysql_info()
PHP includes several functions specifically designed to serve as an interface for MySQL databases, all of which are prefixed with "mysql_".
The purpose of mysql_info(), is to return info about the last query to be executed on a specified connection.
PHP MySQL_Info() Prototype
String: This is the returned information about the last query, in string format. The exact format of this string depends on the type of query last executed. There are five different types of query that mysql_info() will return information about:
Returned String: Records: x Duplicates: y Warnings: z
Statement: INSERT INTO (tablename) [(fieldnames)] SELECT (statement)
Returned String: Records: x Duplicates: y Warnings: z
Statement: LOAD DATA INFILE (filename) INTO TABLE (tablename)
Returned String: Records: w Deleted: x Skipped: y Warnings: z
Statement: ALTER TABLE
Returned String: Records: 60 Duplicates: 0 Warnings: 0
Statement: UPDATE (condition) (new value)
Returned String: Rows matched: x Changed: y Warnings: z
The letters w, x, y and z represent the numbers that correspond to the last query.
These 5 statements are the only valid queries for which information can be returned. If the last query was not one of these statements, then mysql_info() will instead return FALSE.
Link_Identifier: This is where you specify the connection who's last query you would like information on. So if you have two separate connections active at one time, $connection1 and $connection2, and you would like to retrieve information about the last query on $connection2, then you add $connection2 as the paramater:
Using MySQL_Info() in PHP
Let's say we have this table stored in a MySQL table:
| Title | FirstName | Surame |
| Mrs | Bill | Bobbington |
| Mr | Bob | Barrington |
| Mr | Barry | Billington |
Whoops! Bill should be a 'Mr', not a 'Mrs'. First, we require a query to fix this mistake:
Now, we need to execute the query:
In theory, this should have changed 'Mrs' to 'Mr' in the first row. So now if we use mysql_info():
The info contained in $mystring should be: "Rows matched: 1 Changed: 1 Warnings: 0".
Comment: