Welcome Guest, Not a member yet? Register   Sign In
Check whether database exists (using dbforge)
#2

[eluser]aidehua[/eluser]
This tweak seems to do the job - but it might not be the best way to do it:

In /system/database/DB_forge.php, I've changed the create_database function to the following:


Code:
/**
     * Create database
     *
     * @access    public
     * @param    string    the database name
     * @param    bool    insert "if not exists" clause
     * @return    bool
     */
    function create_database($db_name, $ifnotexists = false)
    {
        if($ifnotexists){
            $db_name = "IF NOT EXISTS " . $db_name;
        }
        $sql = $this->_create_database($db_name);
        
        if (is_bool($sql))
        {
            return $sql;
        }
    
        return $this->db->query($sql);
    }

(The original un-altered function looked like thisSmile

Code:
/**
     * Create database
     *
     * @access    public
     * @param    string    the database name
     * @return    bool
     */
    function create_database($db_name)
    {
        $sql = $this->_create_database($db_name);
        
        if (is_bool($sql))
        {
            return $sql;
        }
    
        return $this->db->query($sql);
    }

Any other/better suggestions would be welcome. (As I understand it, it is not possible to extend the DB_forge class in the way you can extend other CI classes by creating a MY_class_name class in the application directory.)


Messages In This Thread
Check whether database exists (using dbforge) - by El Forum - 11-28-2009, 12:03 PM
Check whether database exists (using dbforge) - by El Forum - 11-28-2009, 12:20 PM
Check whether database exists (using dbforge) - by El Forum - 02-09-2010, 03:49 PM



Theme © iAndrew 2016 - Forum software by © MyBB