Skip to content

Commit f6ecbac

Browse files
committed
Deprecate mysqli_stmt_init
1 parent 4226d16 commit f6ecbac

59 files changed

Lines changed: 350 additions & 466 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

NEWS

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ PHP NEWS
6767
. Passing objects to mb_convert_variables() is now deprecated. (Girgias)
6868

6969
- MySQLi:
70-
. The mysqli_get_charset() function is now deprecated. (Kamil Tekiela)
70+
. The mysqli_get_charset() function and mysqli::get_charset() method is now deprecated. (Kamil Tekiela)
71+
. The mysqli_stmt_init() function and mysqli::stmt_init() method are now deprecated. (Kamil Tekiela)
72+
. Instantiation of mysqli_stmt without providing the $query parameter is now deprecated. (Kamil Tekiela)
7173

7274
- PDO:
7375
. Fixed pdo_raise_impl_error() emitting a warning under ERRMODE_SILENT.

UPGRADING

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,11 @@ PHP 8.6 UPGRADE NOTES
471471
RFC: https://wiki.php.net/rfc/deprecations_php_8_6#passing_objects_for_vars_parameter_of_mb_convert_variables
472472

473473
- MySQLi:
474-
. The mysqli_get_charset() function is now deprecated.
474+
. The mysqli_get_charset() function and mysqli::get_charset() method are now deprecated.
475475
RFC: https://wiki.php.net/rfc/deprecations_php_8_6#deprecate_mysqli_get_charset
476+
. The mysqli_stmt_init() function, mysqli::stmt_init() method, and calling mysqli_stmt constructor
477+
without providing the $query parameter are now deprecated.
478+
RFC: https://wiki.php.net/rfc/deprecations_php_8_6#deprecate_mysqlistmt_init
476479

477480
- SPL:
478481
. The spl_classes() function is now deprecated, use

ext/mysqli/mysqli.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,8 @@ PHP_METHOD(mysqli_stmt, __construct)
674674
RETURN_FALSE;
675675
}
676676
mysqli_resource->status = MYSQLI_STATUS_VALID;
677+
} else {
678+
zend_error(E_DEPRECATED, "Instantiation of mysqli_stmt without providing the $query parameter is deprecated");
677679
}
678680
}
679681

ext/mysqli/mysqli.stub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,7 @@ public function stat(): string|false {}
996996
* @tentative-return-type
997997
* @alias mysqli_stmt_init
998998
*/
999+
#[\Deprecated(since: '8.6', message: 'use mysqli::prepare() instead')]
9991000
public function stmt_init(): mysqli_stmt|false {}
10001001

10011002
/**
@@ -1610,6 +1611,7 @@ function mysqli_stmt_get_result(mysqli_stmt $statement): mysqli_result|false {}
16101611
function mysqli_stmt_get_warnings(mysqli_stmt $statement): mysqli_warning|false {}
16111612

16121613
/** @refcount 1 */
1614+
#[\Deprecated(since: '8.6', message: 'use mysqli_prepare() instead')]
16131615
function mysqli_stmt_init(mysqli $mysql): mysqli_stmt|false {}
16141616

16151617
/** @refcount 1 */

ext/mysqli/mysqli_arginfo.h

Lines changed: 17 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/mysqli/tests/bug38710.phpt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ require_once 'skipifconnectfailure.inc';
1111
require_once 'connect.inc';
1212

1313
$db = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
14-
$qry=$db->stmt_init();
15-
$qry->prepare("SELECT REPEAT('a',100000)");
14+
$qry=$db->prepare("SELECT REPEAT('a',100000)");
1615
$qry->execute();
1716
$qry->bind_result($text);
1817
$qry->fetch();

ext/mysqli/tests/bug42378.phpt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,17 @@ memory_limit=83886080
5050

5151
function test_format($link, $format, $from, $order_by, $expected, $offset) {
5252

53-
if (!$stmt = mysqli_stmt_init($link)) {
54-
printf("[%03d] Cannot create PS, [%d] %s\n",
55-
$offset,
56-
mysqli_errno($link), mysqli_error($link));
57-
return false;
58-
}
5953
print "$format\n";
6054

6155
if ($order_by)
6256
$sql = sprintf('SELECT %s AS _format FROM %s ORDER BY %s', $format, $from, $order_by);
6357
else
6458
$sql = sprintf('SELECT %s AS _format FROM %s', $format, $from);
6559

66-
if (!mysqli_stmt_prepare($stmt, $sql)) {
60+
if (!$stmt = mysqli_prepare($link, $sql)) {
6761
printf("[%03d] Cannot prepare PS, [%d] %s\n",
6862
$offset + 1,
69-
mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
63+
mysqli_errno($link), mysqli_error($link));
7064
return false;
7165
}
7266

ext/mysqli/tests/bug55653.phpt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@ require_once 'skipifconnectfailure.inc';
1616

1717
$in_and_out = "a";
1818

19-
if (!($stmt = $link->stmt_init()))
19+
if (!($stmt = $link->prepare("SELECT ?")))
2020
printf("[002] [%d] %s\n", $link->errno, $link->error);
2121

22-
if (!($stmt->prepare("SELECT ?")) ||
23-
!($stmt->bind_param("s", $in_and_out)) ||
22+
if (!($stmt->bind_param("s", $in_and_out)) ||
2423
!($stmt->execute()) ||
2524
!($stmt->bind_result($in_and_out)))
2625
printf("[003] [%d] %s\n", $stmt->errno, $stmt->error);

ext/mysqli/tests/bug66043.phpt

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Bug #66043 (Segfault calling bind_param() on mysqli)
2+
Bug #66043 (Segfault calling bind_param() on mysqli) - Calling mysql_stmt::bind_result() without storing it's result value in a variable is causing a segfault.
33
--EXTENSIONS--
44
mysqli
55
--SKIPIF--
@@ -9,38 +9,13 @@ require_once 'skipifconnectfailure.inc';
99
--FILE--
1010
<?php
1111
require 'connect.inc';
12-
if (!$db = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
13-
printf("[001] Connect failed, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
14-
}
15-
16-
if (!$db->query("DROP TABLE IF EXISTS test")) {
17-
printf("[002] [%d] %s\n", mysqli_errno($db), mysqli_error($db));
18-
die();
19-
}
20-
21-
if (!$db->query("CREATE TABLE test(str TEXT)")) {
22-
printf("[003] [%d] %s\n", mysqli_errno($db), mysqli_error($db));
23-
die();
24-
}
25-
26-
if (!$db->query("INSERT INTO test(str) VALUES ('Test')")) {
27-
printf("[004] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
28-
die();
29-
}
30-
31-
$stmt = $db->stmt_init();
32-
if (!$stmt->prepare("SELECT str FROM test")) {
33-
printf("[004] [%d] %s\n", mysqli_errno($db), mysqli_error($db));
34-
die();
35-
}
12+
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
13+
$db = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
3614

15+
$stmt = $db->prepare("SELECT 'Test'");
3716
$stmt->execute();
3817
$stmt->bind_result($testArg);
3918
echo "Okey";
4019
?>
41-
--CLEAN--
42-
<?php
43-
require_once 'clean_table.inc';
44-
?>
4520
--EXPECT--
4621
Okey

ext/mysqli/tests/mysqli_class_mysqli_stmt_interface.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ printf("stmt->unknown = '%s'\n", @$stmt->unknown);
132132
print "done!";
133133
?>
134134
--EXPECTF--
135+
Deprecated: Instantiation of mysqli_stmt without providing the $query parameter is deprecated in %s on line %d
135136
Parent class:
136137
bool(false)
137138

0 commit comments

Comments
 (0)