#27621 [Opn->Bgs]: sqlite_fetch_array() produces blanks at the third and then every fourth call
| From: | iliaa@php.net | Date: | Wed, 17 Mar 2004 14:34:39 +0000 |
| Subject: | #27621 [Opn->Bgs]: sqlite_fetch_array() produces blanks at the third and then every fourth call | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-56586@lists.php.net to get a copy of this message | ||
ID: 27621
Updated by: iliaa@php.net
Reported By: jo3 at brats dot com
-Status: Open
+Status: Bogus
Bug Type: SQLite related
Operating System: Red Hat Linux release 9 (Shrike)
PHP Version: 5.0.0b4 (beta4)
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2004-03-17 03:15:53] 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
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=27621&edit=1