Documentation

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
v1.4:dblayer [2011/04/01 11:59]
Reines
v1.4:dblayer [2011/04/01 12:04]
Reines [Class synopsis]
Line 6: Line 6:
 <code php> <code php>
 DBLayer { DBLayer {
 + string $prefix
 +
  DBLayer( string $db_host , string $db_username , string $db_password , string $db_name , string $db_prefix , bool $p_connect )  DBLayer( string $db_host , string $db_username , string $db_password , string $db_name , string $db_prefix , bool $p_connect )
  void start_transaction( void )  void start_transaction( void )
Line 35: Line 37:
  bool drop_index( string $table_name , string $index_name [, bool $no_prefix = FALSE] )  bool drop_index( string $table_name , string $index_name [, bool $no_prefix = FALSE] )
  bool truncate_table( string $table_name [, bool $no_prefix = FALSE] )  bool truncate_table( string $table_name [, bool $no_prefix = FALSE] )
 +}
 +</​code>​
 +
 +==== Example usage ====
 +
 +<code php>
 +// Fetch user count
 +$result = $db->​query('​SELECT COUNT(id) FROM '​.$db->​prefix.'​users AS u WHERE u.id>1 AND u.group_id!='​.PUN_UNVERIFIED) or error('​Unable to fetch user list count',​ __FILE__, __LINE__, $db->​error());​
 +$num_users = $db->​result($result);​
 +</​code>​
 +
 +<code php>
 +// Grab the users
 +$result = $db->​query('​SELECT u.id, u.username, u.title, u.num_posts,​ u.registered,​ g.g_id, g.g_user_title FROM '​.$db->​prefix.'​users AS u LEFT JOIN '​.$db->​prefix.'​groups AS g ON g.g_id=u.group_id WHERE u.id IN('​.implode(',',​ $user_ids).'​)'​) or error('​Unable to fetch user list', __FILE__, __LINE__, $db->​error());​
 +while ($user_data = $db->​fetch_assoc($result))
 +{
 + // Do something with $user_data...
 } }
 </​code>​ </​code>​