CHAPTER 11 MODIFYING PHPBB 337 The abstraction

CHAPTER 11 MODIFYING PHPBB 337 The abstraction layer provides all the functionality you need to get data to and from your database. Many methods are available to you to manipulate your data. Table 11-3 lists the functions you ll most commonly use when writing modifications, with their PHP equivalents. Table 11-3. Common Database Abstraction Layer Methods phpBB Method PHP Equivalent Description sql_query($sql) mysql_query() Runs a query on your database using SQL statements defined in $sql. Returns the result of the query if it is successful, and falseif a failure occurred. sql_fetchrow($query_id) mysql_fetch_array() Returns a row of data as requested in the result of sql_query(), or false if a failure occurred. Use this function when you expect only one row of results. The data returned by sql_fetchrow() is an array indexed by field name. For example, to access the field user_name in the returned variable foo, use the notation $foo[’user_name’]. sql_fetchrowset($query_id) Multiple calls to Works just like sql_fetchrow(), except it returns a mysql_fetch_array() multidimensional array containing multiple rows of data. Access the data returned by sql_fetchrowset() by using the notation $foo[$i][’field_name’], where $i is the number (starting with zero) of the result you wish to access. For example, to access the third result of a query on usernames, use the notation $foo[2][’user_name’]. sql_freeresult($query_id) mysql_free_result() Clears out the result of a query and enables you to start fresh. This is a good cleanup method to use, particularly after a large query, to help free memory and keep things running smoothly. Simply pass a result from sql_query() into the function to make it work. Returns true if successful, and false if a failure occurred. The mechanics of these functions are not much different from those of the built-in PHP equivalents. For example, Listing 11-2 shows how to get a post title in PHP format, and Listing 11-3 shows how to use the phpBB abstraction layer to retrieve the same information. Listing 11-2. Retrieving a Post s Information Using Standard PHP
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.

Leave a Reply