php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81262 0 parameters in mysqli_prepare statement
Submitted: 2021-07-15 19:00 UTC Modified: 2021-07-25 04:22 UTC
From: bigarn13 at gmail dot com Assigned: cmb (profile)
Status: No Feedback Package: MySQLi related
PHP Version: 8.0.8 OS: Windows 8
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2021-07-15 19:00 UTC] bigarn13 at gmail dot com
Description:
------------
I want to execute a query that has no parameters. To be consistent, I would like to prepare this query as I do all other queries.

In the Test script below, $stmt = ... executes ok.

When the mysqli_stmt_bind_param(...) is executed the interpreter complains:
Fatal error: Uncaught ValueError: mysqli_stmt_bind_param(): Argument #2 ($types) cannot be empty...

The manual page for mysqli_prepare states that 0 or more place holder ? can appear in the SQL, at the top level (no quotes), only in places where values are expected, etc... My SELECT statement complies with all that.

So I tried deleting the mysqli_stmt_bind_param(...) line, because there are no parameters to bind. In this case, the interpreter complains when the mysqli_stmt_execute($stmt); is executed that no parameters have been bound! But there are no parameters in this SELECT query.

No changes were made tp php.ini

It looks like a core issue to me.

My version of php is reported as PHP version: 8.0.5, so I chose the closest match 8.08 ?

Test script:
---------------
$stmt = mysqli_prepare($con, "SELECT _id, _user_id, _email FROM $members WHERE _user_id IS NULL");
mysqli_stmt_bind_param($stmt, "");
mysqli_stmt_execute($stmt);


Expected result:
----------------
Please provide a workaround or technique I can use now to prepare a query with 0 parameters.


Actual result:
--------------
Stack trace: #0 C:\xampp\htdocs\sample.php(nnn): mysqli_stmt_bind_param(Object(mysqli_stmt), '') #1 {main} thrown in C:\xampp\htdocs\sample.php on line nnn

Patches

0_parameters_in_mysqli_prepare_stmt (last revision 2021-07-15 19:05 UTC by bigarn13 at gmail dot com)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-07-15 19:05 UTC] bigarn13 at gmail dot com
The following patch has been added/updated:

Patch Name: 0_parameters_in_mysqli_prepare_stmt
Revision:   1626375940
URL:        https://bugs.php.net/patch-display.php?bug=81262&patch=0_parameters_in_mysqli_prepare_stmt&revision=1626375940
 [2021-07-15 19:14 UTC] patrickallaert@php.net
There is no reasons to use "prepare" then "execute" for queries without parameters. Use mysqli_query() directly.
 [2021-07-15 19:20 UTC] dharman@php.net
What is $members? Can you show the compiled SQL? 


While Patrick is somewhat right that there is no need to use prepare and execute for static queries, there is also absolutely nothing wrong with using them without placeholders. 

If there is a bug then we would like to be able to reproduce it. Can you please provide the full SQL to reproduce the problem?
 [2021-07-15 19:25 UTC] dharman@php.net
Please also let us know if you are using mysqlnd or some version of libmysqlclient and if so which one?
 [2021-07-16 11:45 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2021-07-25 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 11:01:27 2024 UTC