php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27621 sqlite_fetch_array() produces blanks at the third and then every fourth call
Submitted: 2004-03-17 03:15 UTC Modified: 2004-03-17 09:34 UTC
From: jo3 at brats dot com Assigned:
Status: Not a bug Package: SQLite related
PHP Version: 5.0.0b4 (beta4) OS: Red Hat Linux release 9 (Shrike)
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: jo3 at brats dot com
New email:
PHP Version: OS:

 

 [2004-03-17 03:15 UTC] jo3 at brats dot com
Description:
------------
configured with --with-sqlite

First execute a sqlite_query() which SELECTS from an sqlite database.

Then determine the number of rows through a sqlite_num_rows() call.

Then for each row, call slite_fetch_array() and then echo some data.

The third fetch will be blank, then every fourth one after that.

Reproduce code:
---------------
slightly more than 20 lines but MOST are just the db inserts.

url is http://gamera.brats.com/sqlite/testnum.php

here is the script:

<?php

main(); /* just call main function */

function main()
{

	$conn = sqlite_open("test.db");

	if (!$conn) {
		echo "A Database Connection Error Occurred.";
		exit;
	}

	$qr = sqlite_query($conn, "DROP TABLE test1;");
	$qr = sqlite_query($conn, "CREATE TABLE test1 (name character varying(80));");
	$qr = sqlite_query($conn, "INSERT INTO test1 VALUES('jo0');");
	$qr = sqlite_query($conn, "INSERT INTO test1 VALUES('jo1');");
	$qr = sqlite_query($conn, "INSERT INTO test1 VALUES('jo2');");
	$qr = sqlite_query($conn, "INSERT INTO test1 VALUES('jo3');");
	$qr = sqlite_query($conn, "INSERT INTO test1 VALUES('jo4');");
	$qr = sqlite_query($conn, "INSERT INTO test1 VALUES('jo5');");
	$qr = sqlite_query($conn, "INSERT INTO test1 VALUES('jo6');");
	$qr = sqlite_query($conn, "INSERT INTO test1 VALUES('jo7');");
	$qr = sqlite_query($conn, "INSERT INTO test1 VALUES('jo8');");
	$qr = sqlite_query($conn, "INSERT INTO test1 VALUES('jo9');");
	$qr = sqlite_query($conn, "INSERT INTO test1 VALUES('jo10');");
	$qr = sqlite_query($conn, "INSERT INTO test1 VALUES('jo11');");
	$qr = sqlite_query($conn, "INSERT INTO test1 VALUES('jo12');");
	$qr = sqlite_query($conn, "INSERT INTO test1 VALUES('jo13');");
	$qr = sqlite_query($conn, "INSERT INTO test1 VALUES('jo14');");
	$qr = sqlite_query($conn, "INSERT INTO test1 VALUES('jo15');");
	
	$test_result = sqlite_query($conn, "SELECT * FROM test1;");
	$test_rows = sqlite_num_rows($test_result);
	for($i=0; $i < $test_rows; $i++) {
		$test_array = sqlite_fetch_array($test_result, $i);
		echo "name: " . $test_array["name"] . "<br>\n";
	}

}
?>


Expected result:
----------------
name: jo0
name: jo1
name: jo2
name: jo3
name: jo4
name: jo5
name: jo3
name: jo7
name: jo8
name: jo9
name: jo10
name: jo11
name: jo12
name: jo13
name: jo14
name: jo15


Actual result:
--------------
name: jo0
name: jo1
name:
name: jo3
name: jo4
name: jo5
name:
name: jo7
name: jo8
name: jo9
name:
name: jo11
name: jo12
name: jo13
name:
name: jo15


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-03-17 09:34 UTC] iliaa@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

You are not using sqlite_fetch_array() correctly. The 2nd 
argument is not a row number but rather result_type. 
 
result_type can be used to specify how you want the results 
to be returned. The default value is SQLITE_BOTH which 
returns columns indexed by their ordinal column number and 
by column name. SQLITE_ASSOC causes the array to be indexed 
only by column names, and SQLITE_NUM to be indexed only by 
ordinal column numbers.  
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Fri Dec 02 14:05:53 2022 UTC