Information Functions

Information Functions

CONNECTION_ID()

Returns the connection ID (thread ID) for the connection. Every connection has an ID that is unique among the set of currently connected clients.

CURRENT_USER()

Returns the user name and host name combination for the MySQL account that the server used to authenticate the current client. This account determines your access privileges. The return value is a string in the utf8character set.

DATABASE()

Returns the default (current) database name as a string in the utf8 character set. If there is no default database,DATABASE() returns NULL.

USER()

Returns the current MySQL user name and host name as a string in the utf8 character set.

VERSION()

Returns a string that indicates the MySQL server version. The string uses the utf8 character set.

SELECT CONNECTION_ID();
SELECT CURRENT_USER();
SELECT DATABASE();
SELECT USER();
SELECT VERSION();

FOUND_ROWS()

A SELECT statement may include a LIMIT clause to restrict the number of rows the server returns to the client. In some cases, it is desirable to know how many rows the statement would have returned without the LIMIT, but without running the statement again. To obtain this row count, include a SQL_CALC_FOUND_ROWS option in the SELECT statement, and then invoke FOUND_ROWS() afterward:

SELECT SQL_CALC_FOUND_ROWS emp_no, first_name FROM employees LIMIT 4;
SELECT FOUND_ROWS();

ROW_COUNT()

Returns the number of rows changed, deleted, or inserted by the last statement if it was an UPDATE, DELETE, or INSERT.

SELECT ROW_COUNT();

LAST_INSERT_ID()

Value of the AUTOINCREMENT column for the last INSERT.

SELECT LAST_INSERT_ID();

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.