php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31702 strings returned with 'pg_fetch_result' are incomplete
Submitted: 2005-01-26 11:20 UTC Modified: 2005-01-26 11:34 UTC
From: kevin dot bray at utoronto dot ca Assigned:
Status: Not a bug Package: PostgreSQL related
PHP Version: 5.0.3 OS: Mac OS X 10.3.7
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: kevin dot bray at utoronto dot ca
New email:
PHP Version: OS:

 

 [2005-01-26 11:20 UTC] kevin dot bray at utoronto dot ca
Description:
------------
When using pg_fetch_result to obtain field values (in 
this case, strings), PHP seems to print/echo only the 
first character in the value,

I'm working with the following table (forgive the odd 
test values):

arkhiv=# select * from docsender;
           doctitle           |  sender  
------------------------------+----------
 letter about cheese          | bob
 letter about cheese          | george
 note about peas              | helen
 note about peas              | god
 note about peas              | bob
 

Reproduce code:
---------------
// pg_connect() code omitted above
$result = pg_query("SELECT docSender.sender FROM docSender WHERE docSender.doctitle = 'letter about cheese'");
?>
<table>
<?
$loopCount=0;
$rowCount = pg_num_rows($result);
while ($loopCount < $rowCount){
      $send = pg_fetch_result($result, $loopCount, 0);
?>
<tr>
	<td>
        <? print 'Author: ' . $send['sender']; 
	    ?> 
	</td>	
	<td>
	    <? var_dump($send);
	    ?>
	</td>
</tr>
<?
    $loopCount++;
} //endwhile
?>
</table>

Expected result:
----------------
I expected to see this:

--------------------------------------------
<html>
<table>
<tr>
	<td>
        Author: bob</td>	
	<td>
	    string(3) "bob"
	</td>
</tr>
<tr>
	<td>
        Author: george</td>	
	<td>
	    string(6) "george"
	</td>
</tr>
</table></body>
</html>

Actual result:
--------------
Only the initial characters (ie, 'b' and 'g') of 'bob' 
and 'george' appeared in the first <td> fields:

---------------------------------------------
<html>
<table>
<tr>
	<td>
        Author: b	</td>	
	<td>
	    string(3) "bob"
	</td>
</tr>
<tr>
	<td>
        Author: g	</td>	
	<td>
	    string(6) "george"
	</td>
</tr>
</table></body>
</html>
---------------------------------------------
I inserted "var_dump();" to check if 
postgres was returning the entire value of the field.  
Apparently it is, so the shortened string must result 
from a later (ie PHP) problem.

Thank you for your attention.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-01-26 11:28 UTC] edink@php.net
You're not fetching array but a single value. $send['sender'] becomes $send[0] which is the first char of the string. Just print $send.
 [2005-01-26 11:34 UTC] kevin dot bray at utoronto dot ca
Thanks.  Lesson learned.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 23:01:30 2024 UTC