. Updated Daily. Editions SDA India   SDA Indonesia
JAX Asia 2008 - Conference for Enterprise Java, SOA, Spring, Web Services, Ajax, Agile and more
BUSINESS ENTERPRISE SOLUTIONS ARCHITECTURE INFORMATION SECURITY WIRELESS & MOBILITY DATA & STORAGE DEVELOPMENT HARDWARE













News

Thursday, 22 March 2007

Five Useful Functions for MySQL Data Fetching

 

 

An article over the Any Example web site speaks about five functions for MySQL data fetching. The author says PHP comes with MySQL extension which is rather low-level and requires writing too much code for trivial tasks like error-checked execution of SQL queries, getting single row from SQL table, getting value from SQL table cell, and such. OOP MySQLi extension isn't any better, he comments. In the article the author presents five functions, which simplify majority of real-life MySQL operations.

The five functions, which the author states, are as follows:

  • Function good_query: this function is analogous to mysql_query. It executes query and return result resource— the one, that could be used with standard functions mysql_fetch_row, mysql_fetch_assoc, mysql_num_rows and others, TRUE for successful UPDATE, DELETE, DROP, etc SQL statements or FALSE for failed queries. It has got advantages like built-in error checking, debug logging and is one letter shorter than ‘mysql_query’ and easier to type.
  • Function good_query_list: this function executes (with error checking) query, retrieves first row and returns it as an array. The advantages of this function are call only one good_query_list function instead of mysql_query, mysql_fetch_row, mysql_free_result and debug logging.
  • Function good_query_assoc: it executes (with error checking) query, retrieves first row and returns it as a hash (associative) array. The author says it is very similar to good_query_list ().
  • Function good_query_value: this function executes (with error checking) query, retrieves first cell (first row and first column) and returns it. The advantage of it is that it is simpler than list ($variable) = good_query_list (...) function.
  • Function good_query_table: this function executes (with error checking) SQL query and retrieves entire result table as two-dimensional array. First dimension is rows; second dimension is columns (associative hash). It is extremely useful for loading data to array-based templates.


The author explains all these functions with example codes to facilitate better understanding.

 

Read the Post

 
 
print save email comment

print

save

email

comment

 
 

Search SDA Asia

Free eNewsletter

SDA Asia Magazine Free Download
 
 
 
Copyright @ 2008 SDA Asia Magazine - All Right Reserved Privacy Policy | Terms of Use