• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

how to see if database exists with PDO [duplicate]

phpmysqlpdo


PHP Snippet 1:

$stmt = $pdo->query("SELECT COUNT(*) FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = 'DBName'");
return (bool) $stmt->fetchColumn();

PHP Snippet 2:

        try {
            $conn->exec($sql);
        } catch (PDOException $th) {
            echo "<br> sql error";
        }

Related Snippets

how to redirect the user back to desired URL after login page in PHP?

Input and output values for php into the browser?

Fatal error: [] operator not supported for strings

PHP - Store information with NO database

How to fix " Uncaught TypeError: Argument 1 passed to JpGraphException::defaultHandler() " problem in php 7.1.3 and jpgraph 4.2.6?

Get data from accuweather api url

How to install PHP composer inside a docker container

Laravel Sanctum CSRF not authenticating

What is my SQL missing?

Can't call javascript alert alertify library from PHP

Parsing JSON File to array in PHP

php echo xml documents with header

How to install php_imagick on wamp64

Cannot pass null argument when using type hinting

Laravel MSSQL Server Connection not working

About Contact Privacy policy Terms and conditions