Home >Database >Mysql Tutorial >MySQL: Test connection with query?

MySQL: Test connection with query?

WBOY
WBOYforward
2023-09-17 19:01:071196browse

MySQL: Test connection with query?

Use any of the predefined functions with a select query, or you can use a select query to print some words to test the connection with the query.

The syntax is as follows.

SELECT yourValue;

The selection query for predefined functions is as follows.

The syntax is as follows.

SELECT anyPredefinedFunctionName();

Now you can implement the above syntax to test the connection with the query.

Case 1 - The query is as follows.

mysql> select "This is MySQL" as Display;

The following is the output.

+---------------+
| Display       |
+---------------+
| This is MySQL |
+---------------+
1 row in set (0.00 sec)

Case 2 - The query is as follows.

mysql> select 10*3 as MultiplicationResult;

The following is the output

+---------------------+
| MultiplicationResult|
+---------------------+
| 30                  |
+---------------------+
c1 row in set (0.00 sec)

Here is the select query to know the connection ID of the predefined function.

Case 1 -The query is as follows

mysql> select connection_id() as ConnectionId;

The following is the output

+--------------+
| ConnectionId |
+--------------+
| 8            |
+--------------+
1 row in set (0.00 sec)

Case 2 - Here is the predefined function database( ), used to know the current database name.

The query is as follows

mysql> select database();

The following is the output

+------------+
| database() |
+------------+
| sample     |
+------------+
1 row in set (0.00 sec)

The above is the detailed content of MySQL: Test connection with query?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete