Jump to: navigation, search

PHP ADODB Select Record

From w3cyberlearnings

Contents

PHP ADODB Select Record

Select records and generate table.

Syntax ADODB Select Record

$sql = "SELECT id,first_name,last_name,email FROM {$table} WHERE email IS NOT NULL";

$result = $conn1->Execute($sql);
while (!$result->EOF) {

	echo $result->fields[0];
	echo "<br/>";
	echo $result->fields[1];
	echo "<br/>";
	echo $result->fields[2];
	echo "<br/>";
	echo $result->fields[3];
	echo "<br/>";

	$result->MoveNext();
}

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";

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

if ($result == 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>';


while (!$result->EOF) {
	echo '<tr>';
	echo '<td>'. $result->fields[0].'</td>';
	echo '<td>'. $result->fields[1].'</td>';
	echo '<td>'. $result->fields[2].'</td>';
	echo '<td>'. $result->fields[3].'</td>';
	echo '</tr>';
	$result->MoveNext();
}
?>

Output

Php mysql adodb select 1.png


Related Links


Navigation
Web
SQL
MISC
References