Welcome Guest, Not a member yet? Register   Sign In
Using stored functions in Active Record
#3

[eluser]Alexxz[/eluser]
Another solving method is to make own mysql driver, which improves CI

mysqlex_driver.php
Code:
<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');


require_once(BASEPATH.'database/drivers/mysql/mysql_driver.php');

class CI_DB_mysqlex_driver extends CI_DB_mysql_driver {
    function _update($table, $values, $where)
    {
        foreach($values as $key => $val)
        {
            if( ! strpos($key, '=')){
                $valstr[] = $key." = ".$val;
            } else {
                $valstr[] = $key;
            }
        }
        
        return "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr)." WHERE ".implode(" ", $where);
    }
    
    function _insert($table, $keys, $values)
    {    
        $data = array_combine($keys, $values);
        
        foreach($data as $key => $val)
        {
            if( ! strpos($key, '=')){
                $valstr[] = $key." = ".$val;
            } else {
                $valstr[] = $key;
            }
        }
        
        return "INSERT INTO ".$this->_escape_table($table)." SET ".implode(', ', $valstr);
    }
    
}

The utility and result parts of driver just inherit standard mysql driver.

In configuration file $db['default']['dbdriver'] = "mysqlex";

Now i can write
Code:
$data = array();
$data['state'] = $newstate;
$data["changed = NOW() "] = null;
and the same syntax for $where statement (for $where works without this changes).

Also I want to make 'LIMIT' restrictions for 'DELETE' statement.


Messages In This Thread
Using stored functions in Active Record - by El Forum - 12-17-2007, 12:57 AM
Using stored functions in Active Record - by El Forum - 12-17-2007, 02:06 AM
Using stored functions in Active Record - by El Forum - 12-17-2007, 08:43 AM
Using stored functions in Active Record - by El Forum - 10-06-2008, 01:49 PM



Theme © iAndrew 2016 - Forum software by © MyBB