Probably a little over-engineered, but this works for me!
<?php
function Connect() {
// Standard DB connection to DB2...
$conn = "*LOCAL"; $name = ""; $pwd = "";
$i5link = db2_connect($conn, $name, $pwd);
if (!$i5link)
echo 'Connection failed: '.db2_stmt_error().' :
'.db2_stmt_errormsg();
return $i5link;
}
function getRowCount($i5link, $table) {
$sql = "SELECT count(*) as NUMROWS from $table";
$stmt = db2_exec($i5link,$sql)
or die("Failed
query:".db2_stmt_error().":".db2_stmt_errormsg());
$res = db2_fetch_assoc($stmt);
return ($res);
}
$connection = Connect();
$table = 'sysibm.systbltype';
$rows_array = getRowCount($connection, $table);
$rows = $rows_array['NUMROWS'];
echo "The number of rows in table $table is $rows";
?>
Regards,
Mike
mike.p@xxxxxxxx Cell: (408)679-1011 Office: (815)722-3454
Zend Server for IBM i Beta avilable at
http://www.zend.com/en/products/server/zend-server-5-new-ibmi
-----Original Message-----
From: web400-bounces@xxxxxxxxxxxx [mailto:web400-bounces@xxxxxxxxxxxx]
On Behalf Of Michael Ryan
Sent: Tuesday, May 18, 2010 1:45 PM
To: Web Enabling the AS400 / iSeries
Subject: [WEB400] PHP count rows
Seems simple...I want a count of the number of rows in a table, put that
count into a variable, and then display that variable. Anyone have a
snippet? Thanks...
As an Amazon Associate we earn from qualifying purchases.