AW: AW: AW: [PHP-DB] php and OCI
| From: | Matthias Kopolt | Date: | Tue, 13 Feb 2001 14:30:05 +0000 |
| Subject: | AW: AW: AW: [PHP-DB] php and OCI | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-6576@lists.php.net to get a copy of this message | ||
OK:
imagine you want to find all rows where COLOR = 'foo' :
$st1 = ociparse ($conn, "SELECT count(*) FROM myTable WHERE COLOR =
'foo'");
ociexecute($st1,OCI_DEFAULT);
ocifetch ($st1);
$number_of_rows = ociresult ($st1, 1); //e.g. 372
$st2 = ociparse ($conn, "SELECT ID, NAME FROM myTable WHERE COLOR =
'foo'");
ociexecute($st2,OCI_DEFAULT);
while (ocifetch($st2)) {
echo "<hr> ID : ".ociresult ($st2, 1);
echo "<br> NAME : ".ociresult ($st2, 2);
} //this will return about 372 datarows
$st3 = ociparse ($conn, "SELECT ID, NAME FROM myTable WHERE COLOR = 'foo'
AND ROWNUM <= 10");
ociexecute($st1,OCI_DEFAULT);
while (ocifetch($st3)) {
echo "<hr> ID : ".ociresult ($st3, 1);
echo "<br> NAME : ".ociresult ($st3, 2);
} //this will return max 10 datarows
//remember to ocifreestatement($st..) every ressource when duing continuos
queries
/*
rownum is a metacolumn that is a signed during retrieving data from
database, but before sorting it.
so " where rownum < 11 order by points desc " will not give you the top ten
but, the first 10 entries in the list, ortderd by points.
to overcom that do subselects :
"select * from (select * from table where foocondition order by foo) where
rownum < 10 "
mk