Jump to content


intTableExists()


  • You cannot reply to this topic
No replies to this topic

#1 Cris D.

    Loves Etomite Forums!

  • Developers
  • PipPipPipPip
  • 1,104 posts
  • Gender:Male

Posted 26 February 2009 - 08:31 AM

Checks for the existance of an internal (<your etomite installation prefix>) table.

From the index.php file:
 function intTableExists($table) {
   // Modified 2008-05-10 [v1.1] by Ralph to use FROM clause
   // function to determine whether or not a specific database table exists
   // $table = the table name, including prefix, to check for existence
   // example: $table = "etomite_new_table"
   // Returns boolean TRUE or FALSE
	 if($table == null) return false;
	 $query = "SHOW TABLE STATUS FROM ".$this->dbConfig['dbase']." LIKE '".$table."'";
	 $rs = $this->dbQuery($query);
	 return ($row = $this->fetchRow($rs)) ? true : false;
   }

This API is good to determine whether a table exists and it is often used to wrap an SQL CREATE query that will actually create a table if this API returns false.

NOTE: This API was changed in V1.1 to stop errors of implementation, but the API may cause errors of implementation in older versions of etomite (0.6.1.4 and earlier).

To make a backward compatible implementation, the API can be used like this:

if($etomite->intTableExists('tablename') !== true){
<<insert CREATE table code here>>
}

for v1.1+ it can be used like this:

if(!$etomite->intTableExists('tablename')){
<<insert CREATE table code here>>
}

Edited by Cris D., 03 March 2009 - 06:19 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users