Welcome Guest, Not a member yet? Register   Sign In
Documentation not accurate in Database Forge Class
#1

(This post was last modified: 11-20-2019, 05:40 AM by engel.)

Hi Everyone,

I noticed something not correct on the documentation of Database Forge Class. It say there that $forge->createDatabase() returns TRUE/FALSE based on success of failure. I was testing it today and on failure, it throws an exception instead. Just an FYI.
Reply
#2

It only throws if it is in debug mode:
PHP Code:
    public function createDatabase(string $dbNamebool $ifNotExists false): bool
    
{
        if (
$ifNotExists && $this->createDatabaseIfStr === null)
        {
            if (
$this->databaseExists($dbName))
            {
                return 
true;
            }
            
$ifNotExists false;
        }
        
        if (
$this->createDatabaseStr === false)
        {
            if (
$this->db->DBDebug)
            {
                throw new 
DatabaseException('This feature is not available for the database you are using.');
            }

            return 
false;
        }
        elseif (! 
$this->db->query(sprintf($ifNotExists $this->createDatabaseIfStr $this->createDatabaseStr$dbName$this->db->charset$this->db->DBCollat))
        )
        {
            if (
$this->db->DBDebug)
            {
                throw new 
DatabaseException('Unable to create the specified database.');
            }

            return 
false;
        }

        if (! empty(
$this->db->dataCache['db_names']))
        {
            
$this->db->dataCache['db_names'][] = $dbName;
        }

        return 
true;
    } 

This is set in your Database config (e.g. .env, or app/Config/Database.php) and defaults to 'DBDebug'  => (ENVIRONMENT !== 'production')
Reply




Theme © iAndrew 2016 - Forum software by © MyBB