php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34030 a pg_fetch_row result doesnt make string comparisons
Submitted: 2005-08-08 03:54 UTC Modified: 2005-08-09 21:16 UTC
From: mansilla_g at yahoo dot com Assigned:
Status: Not a bug Package: PostgreSQL related
PHP Version: 4.3.11 OS: linux
Private report: No CVE-ID: None
 [2005-08-08 03:54 UTC] mansilla_g at yahoo dot com
Description:
------------
when you get a string from a pg_fetch_row function it cant be compared with other string correctly, but if you use odbc_fetch_row it works, note that i compare ($row[0] == "Guille"), even if i assign $a = "Guille" and then i try to compare ($row[0] == $a) i get a wrong result, but it i use odbc_fetch_row or odbc_fetch_array instead it works.

Reproduce code:
---------------
<?php
$conn = pg_pconnect("","","","","mydb");
$query = "Select nombre from empleados where id = 1";
$resultado = pg_Exec($conn, $query);
$row = pg_fetch_row($resultado);
echo ($row[0]);
if ($row[0] == "Guille") {
   echo ("$row[0] is = Guille"); } 
else {
   echo ("$row[0] is not Guille");
}
 ?>

Expected result:
----------------
Guille
Guille is = Guille

Actual result:
--------------
Guille
Guille is not Guille

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-08-08 04:26 UTC] mansilla_g at yahoo dot com
i forgot, using "===" doenst work either
but the most interesting if that you compare numbers it works, for example, lets suppose $Row[1] = 34030 then you compare,  if ( $Row[1] == 34030) , it returns true :S
 [2005-08-08 08:57 UTC] sniper@php.net
Instead of that echo $row[0]; do this:

var_dump($row[0]);

 [2005-08-09 01:04 UTC] mansilla_g at yahoo dot com
the result is the same, the trouble is not to print the output, the trouble is that when you retrieve a string this can not be compared, "var_dumping" tells me string(50) "Guille ", so the result is "Guille " i mean $row[0] = "Guille", and the strange is that ( $row[0] == "Guille ") returns false :S
 [2005-08-09 09:10 UTC] sniper@php.net
Can you PLEASE paste the output of the script with var_dump() in it??

 [2005-08-09 09:36 UTC] mansilla_g at yahoo dot com
string(50) "Guille "
 [2005-08-09 10:17 UTC] sniper@php.net
As you see, it's 50 chars long? What type of column is that..? Have you heard about trim() ? :)

 [2005-08-09 21:05 UTC] mansilla_g at yahoo dot com
Yes, you're right, this is not a bug and i apoligeze for making that notice, altough i'd like to know why the same syntax worked using odbc (even when there are blank spaces)? does odbc use trim() ? thank you and once again sorry.
 [2005-08-09 21:16 UTC] tony2001@php.net
No bug -> bogus.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 06 08:01:27 2024 UTC