php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75448 In case of failure, mysqli::prepare() returns NULL instead of FALSE
Submitted: 2017-10-28 03:05 UTC Modified: 2018-09-18 22:27 UTC
From: morozov at tut dot by Assigned: johannes (profile)
Status: Closed Package: MySQLi related
PHP Version: 7.1.11 OS: Linux
Private report: No CVE-ID: None
 [2017-10-28 03:05 UTC] morozov at tut dot by
Description:
------------
According to http://php.net/mysqli_prepare, mysqli_prepare() returns a statement object or FALSE if an error occurred. Under certain circumstances, it also returns NULL which makes error handling harder.

Test script:
---------------
<?php

$conn = mysqli_connect('localhost', 'root', '');
$conn->close();

$stmt = $conn->prepare('SELECT * FROM users');
var_dump($stmt);


Expected result:
----------------
The value of $stmt is FALSE.

Actual result:
--------------
The value of $stmt is NULL.

Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-10-29 08:29 UTC] kalle@php.net
-Type: Bug +Type: Documentation Problem
 [2017-10-29 08:29 UTC] kalle@php.net
I think this is a common thing in the mysqli extension to simply return null if the "active connection" check fails, so instead the docs should be updated to reflect thi
 [2017-10-29 19:25 UTC] morozov at tut dot by
It may be a common thing but it's still a bug. As far as I understand the design, all `mysqli_*` functions should return FALSE on failure, and a user can call `mysqli_error()` and friends to get the error details. What's the point of returning FALSE in some cases but NULL in others?
 [2017-10-30 04:58 UTC] kalle@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: johannes
 [2017-10-30 04:58 UTC] kalle@php.net
Hi

Yes its a bug in the documentation, because the mysqli functionality has always been like this. Your PR changes every place where the check is performed to return false, while I understand that its easier to just have one common fault value to check, and I do agree it makes sense, it does introduce a minor BC break, while still minor, I'm still more reluctant to fix the docs.

@johannes can you please come with some input on this from a mysql standpoint?
 [2018-09-18 22:27 UTC] morozov at tut dot by
-Status: Assigned +Status: Closed -Type: Documentation Problem +Type: Bug
 [2018-09-18 22:27 UTC] morozov at tut dot by
Marking it as resolved by https://github.com/php/php-src/pull/2885.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 15:01:30 2024 UTC