News:

Please note these forums are mostly a testing ground for my SMF work and I don't really use them otherwise.

Main Menu

Paste-1268761867:v:use_geshi-1:v:type-php

Started by SleePy, Mar 16, 2010, 05:51 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

SleePy

// SleePy is lazy, so I will just check to see if db_query exists
if(!function_exists('db_query'))
{
   db_extend('Packages');
   function db_query($query, $file, $line)
   {
      global $smcFunc;
      return $smcFunc['db_query']('', $query, array('db_error_skip' => true));
   }
}
// All work here is for back support for SMF 1.1, It is easier to support 2.0 and backport.
else
{
   $smcFunc = $func;
   $smcFunc['db_num_rows'] = 'mysql_num_rows';
   $smcFunc['db_free_result'] = 'mysql_free_result';
   $smcFunc['db_fetch_assoc'] = 'mysql_fetch_assoc';
   $smcFunc['db_list_columns'] = 'mysql_show_columns';
   $smcFunc['db_add_column'] = 'mysql_create_columns';

   // Quickly emulate these functions.
   function mysql_show_columns($table_name)
   {
      global $smcFunc, $db_prefix;

      $result = db_query("SHOW FIELDS FROM {$table_name}", __FILE__, __LINE__);;
      $columns = array();
      while ($row = $smcFunc['db_fetch_assoc']($result))
         $columns[] = $row['Field'];
      return $columns;
   }
   function mysql_create_columns($table_name, $column_info)
   {
      global $db_prefix;

      return db_query('ALTER TABLE ' . $table_name . '
         ADD ' . $column_info['name'] . ' ' . $column_info['type'] . ' ' . (empty($column_info['null']) ? 'NOT NULL' : '') . ' ' .
      (empty($column_info['default']) ? '' : 'default \'' . $column_info['default'] . '\'') . ' ' .
      (empty($column_info['auto']) ? '' : 'auto_increment') . ' ', __FILE__, __LINE__);
   }
}
No siggy! :D