Jump to: navigation, search

PHP ADODB FETCH NUM

From w3cyberlearnings

Contents

PHP ADODB_FETCH_NUM

Fetch records as indexes. First field is index 0, second field index 1, and so on.

Syntax ADODB_FETCH_NUM

$table = 'user_infor';
$sql = "SELECT id,first_name,last_name,email FROM {$table} WHERE email IS NOT NULL";
$conn1->SetFetchMode(ADODB_FETCH_NUM);

$results = $conn1->Execute($sql);
foreach($results as $result) {
	echo  $result[0] . '<br/>';
	echo  $result[1] . '<br/>';
	echo  $result[2] . '<br/>';
	echo  $result[3] . '<br/>';
	
}

Example 1

<?php

include 'adodb5/adodb.inc.php';

$host = 'localhost';
$user = 'user2000';
$pass = 'password2000';
$dbname = 'w3cyberlearning';

$conn1 = &ADONewConnection('mysql');
$conn1->PConnect($host, $user, $pass, $dbname);
$table = 'user_infor';
$sql = "SELECT id,first_name,last_name,email FROM {$table} WHERE email IS NOT NULL";
$conn1->SetFetchMode(ADODB_FETCH_NUM);

$results = $conn1->Execute($sql);

if ($results == false) {
	print 'error' . $conn1->ErrorMsg() . '<br>';
}

$table_meta = $conn1->MetaColumns($table);
$table_header = array_keys($table_meta);

echo '<table border="1">';
// generate and display header from table field
echo '<tr>';
foreach ($table_header as $colname) {
	echo '<th>' . $colname . '</th>';
}
echo '</tr>';


foreach($results as $result) {
	echo '<tr>';
	echo '<td>' . $result[0] . '</td>';
	echo '<td>' . $result[1] . '</td>';
	echo '<td>' . $result[2] . '</td>';
	echo '<td>' . $result[3] . '</td>';
	echo '</tr>';
}
?>

Output

Php mysql adodb select 1.png


Related Links


Navigation
Web
SQL
MISC
References