MySQL built-in functions can help us process data in the table more conveniently and simplify operations.
Mathematical functions:
Function | Description |
---|---|
Take absolute Value | |
Take the root | |
Take the modulo | |
Returns the largest integer value that is not greater than | |
Returns is not less than The smallest integer value | |
Rounding | |
Take the sine | |
Get cosine |
Description | |
---|---|
LOWER() | |
UPPER() | |
TRIM() | |
REPLACE() | |
CURDATE() | |
CURTIME() | |
YEAR() | |
MONTH() | |
DAY() | |
date_format() | |
MAX() | |
MIN() | |
SUM () | |
IFNULL | |
CASE WHEN | |
<?php # 创建连接 $conn = mysqli_connect("localhost", "root", "admin", "study"); # 查看是否连接成功 if ($conn) { echo "服务器连接成功!\n"; } else { echo mysqli_connect_error(); } # SQL语句, 函数使用 $SQL = "SELECT count(*) FROM user"; # 执行SQL语句 $result = mysqli_query($conn, $SQL); # 查看是否执行成功 if ($result) { echo "SQL语句执行成功!\n"; } else { echo mysqli_error($conn); } # 调试输出 while ($line = mysqli_fetch_assoc($result)) { print_r($line); } # 关闭连接 mysqli_close($conn); ?>
Server connection successful!
SQL statement executed successfully!Array##Example 2(
[count(*) ] => 5
)
Get the highest salary:
<?php # 创建连接 $conn = mysqli_connect("localhost", "root", "admin", "study"); # 查看是否连接成功 if ($conn) { echo "服务器连接成功!\n"; } else { echo mysqli_connect_error(); } # SQL语句, 函数使用 $SQL = "SELECT max(salary) FROM user"; # 执行SQL语句 $result = mysqli_query($conn, $SQL); # 查看是否执行成功 if ($result) { echo "SQL语句执行成功!\n"; } else { echo mysqli_error($conn); } # 调试输出 while ($line = mysqli_fetch_assoc($result)) { print_r($line); } # 关闭连接 mysqli_close($conn); ?>
SQL statement executed successfully!
Array([max(salary)] => 30000.00
)
The above is the detailed content of How to use built-in functions in MySQL and PHP. For more information, please follow other related articles on the PHP Chinese website!