Differences

This shows you the differences between the selected revision and the current version of the page.

punbb13:integration 2010/03/29 06:33 punbb13:integration 2020/02/06 11:04 current
Line 23: Line 23:
  - Choose the URL scheme you like and save changes.   - Choose the URL scheme you like and save changes.
-===== Database helpers ===== 
-On ''include/common.php'' inclusion, the proper implementation of [[database layer]] class is being also included according to forum configuration. 
-An instance of this database layer named ''$forum_db'' is being created in global scope to provide [[database helpers]]. 
- 
-==== How to perform a query ==== 
-  * Direct query. You can simply write an SQL-statement and execute it. 
-<code php> $result = $forum_db->query('SELECT * FROM topics WHERE id = 10');</code> 
-Be sure, that your SQL code is cross-compatible with all database engines supported by PunBB. 
-  * Using [[query builder]]. You may transparently build database queries. All the specific of database engines and database structure will automatically be taken in account. Example of usage (FIXME make it more informative): 
-<code php>$query = array( 
-  'SELECT'  => '*', 
-  'FROM'    => 'topics', 
-  'WHERE'  => 'id = 10' 
-); 
-$result = $forum_db->query_build($query); 
-</code> 
-See [[query builder]] page for details. 
-==== How to work with query results ==== 
-For example, we have this query: 
-<code php> 
-  $query = array( 
-    'SELECT' => 't.id, t.poster, t.subject, t.posted', 
-    'FROM'  => 'topics AS t', 
-    'WHERE'  => 't.forum_id = 1' 
-  ); 
-  $result = $forum_db->query_build($query) or error(__FILE__, __LINE__); 
-</code> 
-  * To know how many rows this query returns, use this: 
-<code php> 
-  $forum_db->num_rows($result); 
-</code> 
-  * To fetch the current row to associative array: 
-<code php> 
-  $data = $forum_db->fetch_assoc($result); 
-  //An example of getting topic_id 
-  $topic_id = $data['id']; 
-</code> 
-  * To fetch the current row to numeric array: 
-<code php> 
-  $data = $forum_db->fetch_row($result); 
-  //An example of getting topic_id 
-  $topic_id = $data[0]; 
-</code> 
-  * To fetch only some values from the current row: 
-<code php> 
-  //This code will fetch only the topic id and the topic subject 
-  list($id,, $subject,) = $forum_db->fetch_row($result); 
-</code> 
-  * To process all rows in a set you can use this code: 
-<code php> 
-  while ($cur_row = $forum_db->fetch_assoc($result)) 
-  { 
-    //Actions with $cur_row 
-  } 
-</code> 
===== Template customization ===== ===== Template customization =====

Personal Tools