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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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: Thu Dec 26 18:01:31 2024 UTC