mysql_info function in PHP

What is mysql_info() function in PHP?
How does mysql_info() works?

Explanation

The mysql_info() function returns information about the last query.
Syntax
string mysql_info ( [resource link_identifier])

Returns information about the last executed query statement on success, or FALSE on failure.
mysql_info() returns detailed information about the last executed query using the given link_identifier. If link_identifier is not specified, the last connection opened by mysql_connect() or mysql_pconnect() link is assumed.
There are five different types of query that mysql_info() will return information about:

Statement: INSERT [INTO] (tablename) [(fieldnames)] VALUES (values)
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


Example

<?php
//Attempt to connect to the default database server
$link = mysql_connect("mysql_host", "mysql_user", "mysql_password")
or die ("Could not connect");
//select database
mysql_select_db('database');
$query = "UPDATE People SET Title = 'Mr' WHERE FirstName='Bill'";
//execute query
$result = mysql_query($query);
//print mysql_info function result
printf("Query Information: %sn", mysql_info()");
?>

In the above code, update query is executed to change the record based on the query condition. After the successful execution of update query mysql_info() function will return string containing query information.
RESULT:
Query Information : Rows matched: 1 Changed: 1 Warnings: 0
Above Query Information represent one row matched and one row changed based on query condition and zero warnings.
See also: mysql_affected_rows().

PHP Topics


Ask Questions

Ask Question