Zend - The PHP Company




Abstraction Layers

Add Code


ezSQL  

Type: application
Added by: jv22
Entered: 21/10/2002
Last modified: 31/10/2007
Rating: **** (5 votes)
Views: 6529
ezSQL is a widget that makes it ridiculously easy for you to use mySQL or Oracle8 database(s) within your PHP scripts (more db's coming soon).


<?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!";
}
?>


Usage Example


See the example


Rate This Script





Search



This Category All Categories