Welcome Guest, Not a member yet? Register   Sign In
DBForge - Create table with Engine MyISAM
#7

[eluser]yacman[/eluser]
The least path of resistance, if you wish to have MYISAM exclusively is to overload the CI_DB_Forge_mysql class. To do this you will need to create a MY_Loader.php class file located in your application/core folder.

This is from the sparks generated loader class, abreviated with the additional dbforge overload.
Code:
<?php  if (! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Sparks
*
* An open source application development framework for PHP 5.1.6 or newer
*
* @package  CodeIgniter
* @author  CodeIgniter Reactor Dev Team
* @author      Kenny Katzgrau <[email protected]>
* @since  CodeIgniter Version 1.0
* @filesource
*/

/**
* Loader Class
*
* Loads views and files
*
* @package  CodeIgniter
* @subpackage Libraries
* @author  CodeIgniter Reactor Dev Team
* @author      Kenny Katzgrau <[email protected]>
* @category Loader
* @link  http://ellislab.com/codeigniter/user-guide/libraries/loader.html
*/
class MY_Loader extends CI_Loader
{
   ...

// --------------------------------------------------------------------

/**
  * Load the Database Forge Class
  *
  * @return string
  */
public function dbforge()
{
  if ( ! class_exists('CI_DB'))
  {
   $this->database();
  }

  $CI =& get_instance();

  require_once(BASEPATH.'database/DB_forge.php');
  require_once(BASEPATH.'database/drivers/'.$CI->db->dbdriver.'/'.$CI->db->dbdriver.'_forge.php');
  /* Look for overload files in the /application/core folder */
  if (file_exists(BASEPATH.'../'.APPPATH.'core/MY_CI_DB_'.$CI->db->dbdriver.'_forge.php')) {
   require_once(BASEPATH.'../'.APPPATH.'core/MY_CI_DB_'.$CI->db->dbdriver.'_forge.php');
   $class = 'MY_CI_DB_'.$CI->db->dbdriver.'_forge';
  } else {  
   $class = 'CI_DB_'.$CI->db->dbdriver.'_forge';
  }

  $CI->dbforge = new $class();
}
}

Next Create a file in your application/libraries folder called:
MY_CI_DB_mysql_forge.php
Code:
&lt;?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
* MySQL Forge Class Force MYISAM
*
* @category Database
* @author
* @link
*/
class MY_CI_DB_mysql_forge extends CI_DB_mysql_forge {
// --------------------------------------------------------------------


/**
  * Create Table
  *
  * @access private
  * @param string the table name
  * @param mixed the fields
  * @param mixed primary key(s)
  * @param mixed key(s)
  * @param boolean should 'IF NOT EXISTS' be added to the SQL
  * @return bool
  */
function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists)
{

  $sql = 'CREATE TABLE ';

  if ($if_not_exists === TRUE)
  {
   $sql .= 'IF NOT EXISTS ';
  }

  $sql .= $this->db->_escape_identifiers($table)." (";

  $sql .= $this->_process_fields($fields);

  if (count($primary_keys) > 0)
  {
   $key_name = $this->db->_protect_identifiers(implode('_', $primary_keys));
   $primary_keys = $this->db->_protect_identifiers($primary_keys);
   $sql .= ",\n\tPRIMARY KEY ".$key_name." (" . implode(', ', $primary_keys) . ")";
  }

  if (is_array($keys) && count($keys) > 0)
  {
   foreach ($keys as $key)
   {
    if (is_array($key))
    {
     $key_name = $this->db->_protect_identifiers(implode('_', $key));
     $key = $this->db->_protect_identifiers($key);
    }
    else
    {
     $key_name = $this->db->_protect_identifiers($key);
     $key = array($key_name);
    }

    $sql .= ",\n\tKEY {$key_name} (" . implode(', ', $key) . ")";
   }
  }

  $sql .= "\n) ENGINE=MYISAM DEFAULT CHARACTER SET {$this->db->char_set} COLLATE {$this->db->dbcollat};";

  return $sql;
}
}

Adding these will enable the $this->dbforge->create_table() method to return the sql for a MYISAM table.

If you have access to the mysql instance, you could force the default table engine to be MYISAM or whatever using the --default-storage-engine or --default-table-type at startup.

This is a pretty good write up I found as well for older versions of CI


Messages In This Thread
DBForge - Create table with Engine MyISAM - by El Forum - 07-25-2011, 07:34 AM
DBForge - Create table with Engine MyISAM - by El Forum - 07-25-2011, 07:38 PM
DBForge - Create table with Engine MyISAM - by El Forum - 07-26-2011, 12:06 AM
DBForge - Create table with Engine MyISAM - by El Forum - 07-26-2011, 03:36 PM
DBForge - Create table with Engine MyISAM - by El Forum - 07-27-2011, 12:40 AM
DBForge - Create table with Engine MyISAM - by El Forum - 07-27-2011, 05:17 AM
DBForge - Create table with Engine MyISAM - by El Forum - 09-12-2012, 09:15 AM
DBForge - Create table with Engine MyISAM - by El Forum - 02-09-2013, 07:15 PM
DBForge - Create table with Engine MyISAM - by El Forum - 12-28-2013, 08:56 AM



Theme © iAndrew 2016 - Forum software by © MyBB