<?php // Note: In all these examples no other code
// is required other than including "ez_sql.php"
// available from http://php.justinvincent.com
//----------------------------------------------------
// Example 1
//----------------------------------------------------
// Print list of products directly from the db within a foreach loop.. foreach( $db->get_col("SELECT product FROM products") as $item )
{
echo "$item";
}
//----------------------------------------------------
// Example 2
//----------------------------------------------------
// Select multiple records from the database and print them out.. $users = $db->get_results("SELECT name, email FROM users");
foreach ( $users as $user )
{
// Access data using object syntax
echo $user->name;
echo $user->email;
}
//----------------------------------------------------
// Example 3
//----------------------------------------------------
// Get one row from the database and print it out.. $user = $db->get_row("SELECT name,email FROM users WHERE id = 2");
echo $user->name;
echo $user->email;
//----------------------------------------------------
// Example 4
//----------------------------------------------------
// Get one variable from the database and print it out.. if ( $u_count = $db->get_var("SELECT count(*) FROM users"))
{
echo "There were $u_count users!";
} ?>
|
|