MySQL: Test connection with query?

WBOY
Release: 2023-09-17 19:01:07
forward
1114 people have browsed it

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;
Copy after login

The selection query for predefined functions is as follows.

The syntax is as follows.

SELECT anyPredefinedFunctionName();
Copy after login

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;
Copy after login

The following is the output.

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

Case 2- The query is as follows.

mysql> select 10*3 as MultiplicationResult;
Copy after login

The following is the output

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

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;
Copy after login

The following is the output

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

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

The query is as follows

mysql> select database();
Copy after login

The following is the output

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

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!