php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42278 mysql_query or die(): unusual behaviour
Submitted: 2007-08-12 14:57 UTC Modified: 2007-08-12 15:31 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: adam at omega dot org dot uk Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 5.2.4RC1 OS: Linux
Private report: No CVE-ID: None
 [2007-08-12 14:57 UTC] adam at omega dot org dot uk
Description:
------------
There is some unusual behaviour in the attached function.  When a new Database object is created, and a query called by:

$result = $this->db_connection->query($valid_sql_query);

Different results will occur, depending on the layout of the Database::query method.

PHP version: 5.2.2
I do not own the webserver, and I doubt that they will be willing to upgrade to an unstable version to test it.

Reproduce code:
---------------
Works:
class Database{
    function query($_sql)
    {
        $q = mysql_query($_sql)or die("Invalid Query: $_sql <br />" . mysql_error());
		return $q;
    }
}

---

Returns true:
class Database{
    function query($_sql)
    {
        return mysql_query($_sql) or die("Invalid Query: $_sql <br />" . mysql_error());
    }
}

---

Works:
class Database{
    function query($_sql)
    {
        return mysql_query($_sql);
    }
}

Expected result:
----------------
In all cases, a mysql resource should be returned.

Actual result:
--------------
In cases 1 and 3 a mysql result is returned.  In case 2, the function simply returns true.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-12 15:31 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

The operator \"or\" is a boolean operator therefore you\'re returning a boolean result of that operation.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jun 18 01:01:32 2024 UTC