• 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

loop through an anchor id

html-php form submission after validation through JavaScript [closed]

How should I get started using PHPUnit as a testing framework for a bunch of functions and classes I have already made?

Unable to match results of php hash_hmac() and coldfusion hmac()

Facebook PHP SDK - will not logout properly

PHP Startup Unable to load dynamic library /usr/lib/php/20151012/php_mysqli.dll

Symfony/Form add attribute based on the data

Warning: A non-numeric value encountered

Laravel 5.5 change unauthenticated login redirect url

Get image type from base64 encoded src string

How to get result of the formula on import xlsx with maatwebsite using Laravel? I get formula and not value of the formula

Nginx disallowing execution of PHP in uploads directory with Magento

How Can I Do LIMIT 1, 2 In WP_Query

Fatal error: Array callback has to contain indices 0 and 1

How to debug in WooCommerce 3+

About Contact Privacy policy Terms and conditions