Noel ST Noel ST - 1 year ago 93
SQL Question

Number of rows obtained from an sql query from php

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">




// extract all the form fields and store them in variables

// the table will always have at three columns
$tablewidth = 600;

$sqlstatement = "SELECT * FROM wine1";

/* Set oracle user login and password info */
$dbuser = "xxxx"; /* your login */
$dbpass = "xxxx"; /* your password */
$db = "SSID";
$connect = oci_connect($dbuser, $dbpass, $db);

if (!$connect) {
echo "An error occurred connecting to the database";

/* build sql statement using form data */
$query = $sqlstatement;

/* check the sql statement for errors and if errors report them */
$stmt = oci_parse($connect, $query);

echo "SQL: $query<br>";

if(!$stmt) {
echo "An error occurred in parsing the sql string.\n";

while(oci_fetch_array($stmt)) {

echo "Number of items: $howmany<br>";



Hello, for the above code. I am trying to count the number of rows returned from an oracle server when i run the "SELECT * from wine1;" query.

It seems the the $count is zero after running the code

I have confirmed that I am able to retrieve all six items stored in the table when submitting the query in the SQL server itself. It just doesn't seem to work in php.

Answer Source

Use this in your case

$numrows = oci_fetch_all($stmt, $res);
echo 'Total rows: '.$numrows;

for iterating all records use this

foreach($res as $rows) { 


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download