• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Documentation not accurate in Database Forge Class

#1
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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.