Function mysqli_execute is Deprecated in PHP 8.5

Function mysqli_execute is Deprecated in PHP 8.5

MySQLi extension provides the mysqli_execute function, which is an alias of mysqli_stmt_execute function. The name mysqli_execute is misleading, because the function operates on mysqli_stmt objects rather than on mysqli connection objects, often causing confusion for developers reading or maintaining code. It also offers no functional advantage, making it redundant alongside the clearer and more descriptive mysqli_stmt_execute function.

Since PHP 8.5, the mysqli_execute function is deprecated:

<?php

$conn = mysqli_connect('127.0.0.1', 'root', 'root', 'testdb');

$stmt = mysqli_prepare($conn, 'INSERT INTO countries (ison, name, code) VALUES (?, ?, ?)');
mysqli_stmt_bind_param($stmt, 'sss', $ison, $name, $code);

$ison = '840';
$name = 'United States';
$code = 'US';
mysqli_execute($stmt);

mysqli_stmt_close($stmt);
mysqli_close($conn);

Example will output:

Deprecated: Function mysqli_execute() is deprecated since 8.5, use mysqli_stmt_execute() instead ...

In the previous example, the deprecation can be fixed by replacing mysqli_execute with mysqli_stmt_execute, ensuring the code uses the preferred and unambiguous function:

<?php

$conn = mysqli_connect('127.0.0.1', 'root', 'root', 'testdb');

$stmt = mysqli_prepare($conn, 'INSERT INTO countries (ison, name, code) VALUES (?, ?, ?)');
mysqli_stmt_bind_param($stmt, 'sss', $ison, $name, $code);

$ison = '840';
$name = 'United States';
$code = 'US';
mysqli_stmt_execute($stmt);

mysqli_stmt_close($stmt);
mysqli_close($conn);

Leave a Comment

Cancel reply

Your email address will not be published.