• 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 pass security cloudflare server with php curl

Remove country code from phone number?

Laravel - Browser displays message again when I press back button

Loading data from MySQL and populating dropdown select with jQuery Mobile, PHP

Yii2: How to download backup files using spanjeta/yii2-backup?

Pages are working fine on localhost but not running on the hosting server

How to separate letters and digits from a string in php

Required field only if another field has a value, must be empty otherwise

How to add automatically collapse/expand in content wordpress (single.php)?

How can I stop a symfony process which is listening on http://127.0.0.1:8000

Laravel Unknown Column 'updated_at'

PHP | "The requested PHP extension bcmath is missing from your system."

PHP: Print caught exception like Xdebug

PHP: How to solve ob_start() in combination imagepng() issue?

Comma separated list from array with "and" before last element

About Contact Privacy policy Terms and conditions