Andrew Glanville on Mon, 07 Apr 2003 14:43:20 +0200 (SAST)


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

[Linux dev] Re: PHP


Hi Paulo,

There are numerous methods - here are they two that I would alternate between 
(depending on the size of the project).

Ordinary:
<?php
$dbh = mysql_connect('host', 'user', 'password');
$dbi = mysql_select_db('dbname', $dbh);

$select_sql = "SELECT * FROM foo";
$select_do = mysql_query($select_sql);
while ($select_entries = mysql_fetch_array($select_do))
{
	print "<td>\n";
	print $select_entries['field_name'];
	print "</td>\n";
	// for more complex display results, consider breaking out of
	// interpret mode into render mode - PHP switches between
	// the two faster than using echo or print, etc.
}
?>

ADOdb:
ADOdb is an awesome database abstraction class for PHP (grab it from 
http://php.weblogs.com )
<?

include_once('adodb.inc.php');
$db = NewADOConnection('mysql');
$db->Connect('host', 'user', 'password', 'dbname');
$select = $db->Execute('SELECT * FROM foo');
while (!$select->EOF)
{
	print "<td>\n";
	print $select->fields['field_name'];
	print "</td>\n";
	$select->MoveNext();
}

?>

With Kind Regards,
Andrew Glanville

PS.  Have a look at http://www.php.net/manual/en/ref.mysql.php and have a look 
at all the mysql_fetch_* functions.

> <?
> while ($data=mysql_fetch_row($result))
> {
>  print" <td> \n";
>  print"  $data[0] \n";
>  print" </td> \n";
> }

---
To unsubscribe: send the line "unsubscribe dev" in the subject of a
mail to dev-request@xxxxxxxxxxxxx Problems: dev-admins@xxxxxxxxxxxx
Archives at http://www.linux.org.za/Lists-Archives/