AbstractConnection::hasDatabase

Check if the database exists or not.

@param string $databaseName The database name.

@return bool Returns false if database doesn't exists.
@throws \O2System\Spl\Exceptions\RuntimeException
499326
final public function hasDatabase($databaseName)
    {
        if (empty($this->queriesResultCache[ 'databaseNames' ])) {
            $this->getDatabases();
        }

        return (bool)in_array($databaseName, $this->queriesResultCache[ 'databaseNames' ]);
    }
371013
public static function isUser(string $username): bool {
		$userdbname = setup::getValidation("username");
		if (R::findOne('user', ' ' . $userdbname . ' = ? ', [$username])) {
			return true;
		}

		return false;
	}
71369
public function exists(array $options = [])
    {
        try {
            $this->connection->getSession($options + [
                'name' => $this->name(),
                'database' => $this->database
            ]);

            return true;
        } catch (NotFoundException $e) {
            return false;
        }
    }
363054
public function serviceExists(string $serviceName): bool {
        return isset($this->serviceData[$serviceName]) || in_array($serviceName, $this->getSelfReferenceNames()) ? true : false;
    }
560182
public function has( $id )
	{
		return \DB::select( $this->table )
			->where( 'id', $id )
			->column( 'id', $this->database ) == $id;
	}
1281325
public function getDatabase ($key)
    {
        if (array_key_exists($key, $this->database)) {
            return $this->database[$key];
        }

        return false;
    }
1074373
public function getDatabase($databaseName = null) {
		if ($databaseName === null) {
			$databaseName = $this->dbname;
		}

		if (! isset($this->databases[$databaseName])) {
			$this->databases[$databaseName] = $this->getClient()->selectDB($databaseName);
		}

		return $this->databases[$databaseName];
	}
783725
public function existDatabase(string $dbName): bool
    {
        $sql = 'SELECT SCHEMA_NAME
            FROM INFORMATION_SCHEMA.SCHEMATA
            WHERE SCHEMA_NAME = %s;';

        $sql = sprintf($sql, $this->quoter->quoteValue($dbName));
        $row = $this->db->query($sql)->fetch(PDO::FETCH_ASSOC);

        return !empty($row['SCHEMA_NAME']);
    }
297365
protected function tableExists($tableName)
    {
        $tables = $this->connection->getSchemaManager()->listTables();

        foreach ($tables as $table) {
            if ($table->getName() == $tableName) {
                return true;
            }
        }

        return false;
    }
536905
final public static function getDbInstance(string $databaseName = '#none'):\PDO
    {
        if (self::$co_instance == null) {
            new self($databaseName);
        }
        return (self::$co_instance);
    }
1370587
public function tableExists($tableName) {
        $tables = $this->query("SHOW TABLES");
        foreach ($tables as $k => $table) {
            $key = 'Tables_in_' . $this->config['table'];
            if (strtolower($table[$key]) == strtolower($this->getPrefix() . $tableName)) {
                return TRUE;
            }
        }
        return FALSE;
    }
1106351
protected function tableExist($tableName)
    {
        /** @var \Doctrine\DBAL\Schema\AbstractSchemaManager $sm */
        $sm = $this->dbHandler->getConnection()->getSchemaManager();
        foreach ($sm->listTables() as $table) {
            if ($table->getName() == $tableName) {
                return true;
            }
        }

        return false;
    }
1221018
public function exist($keyName) : bool
    {
        # double check
        return
            $this->get($keyName, true) !== true
            && $this->get($keyName, false) !== false;
    }
675433
public function select($database)
	{
		if (empty($database))
		{
			return false;
		}

		$this->connection->exec('USE ' . $this->quoteName($database));

		$this->database = $database;

		return true;
	}
66779
private function isDatabaseExist()
    {
        $databaseName = $this->getContainer()->getParameter('database_name');

        try {
            /** @var MySqlSchemaManager $schemaManager */
            $schemaManager = $this->getContainer()->get('doctrine')->getManager()->getConnection()->getSchemaManager();
        } catch (\Exception $exception) {
            $message = "SQLSTATE[42000] [1049] Unknown database '%s'";
            if (false !== strpos($exception->getMessage(), sprintf($message, $databaseName))) {
                return false;
            }

            throw $exception;
        }

        try {
            return in_array($databaseName, $schemaManager->listDatabases());
        } catch(\PDOException $e) {
            return false;
        }
    }
451795
public function checkTableExists(string $tableName): bool
    {
        try {
            $result = $this->pdo->query("SELECT 1 FROM $tableName LIMIT 1");
        } catch (\Exception $e) {
            return false;
        }

        return $result !== false;
    }
1122505
public function exists()
    {
        if (!Data::table($this->name)->exists())
            throw new dbException('Table "' . $this->name . '" does not exists');

        if (!Config::table($this->name)->exists())
            throw new dbException('Config "' . $this->name . '" does not exists');

        return true;
    }