POW(base, exponent) calculates exponentiation in MySQL. POWER() is a synonym.
Run this SELECT query directly in MySQL or phpMyAdmin. It uses fixed inputs so you can verify the result without creating a table.
SELECT POW(3, 4) AS power_value;| power_value |
|---|
| 81 |
SELECT POW(5, 2);
Output of this is
25
For negative
SELECT POW(4, -2);
Output is
0.0625
require 'config.php'; // Database connection
$stmt = $dbo->prepare(
'INSERT INTO sql_pow (a, b) VALUES (:a, POW(:base, 2))'
);
for ($i = 1; $i <= 10; $i++) {
$stmt->execute(['a' => $i, 'base' => $i]);
}
An exponent can be negative. Use SQRT() for square roots and be careful with out-of-range results.
Are POW() and POWER() different?
No. MySQL treats POWER() as a synonym for POW().
Database example: The PHP insertion sample above needs the matching table and a configured database connection. The standalone POW() queries do not.
More related tutorials: All math functions, COS(), DEGREES()
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.