• 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

Phpunit partial mock + proxy Entity

AJAX call fails with SyntaxError: Unexpected end of JSON input

Warning file_get_contents () failed to open stream: HTTP request failed! HTTP/1.0 402 Payment Required

Upgrade PHP on AWS Linux

Lexik JWT authentication problem "Invalid credentials"

PHP date() with timezone?

php - add comma thousands separator but remove trailing zeros

Laravel whole batch is cancelled if one Job fails

Backend cannot be reached after Typo3 login screen

Match single unknown parameter php (Morse-code Regex)

What is PHP's equivalent of JavaScript's "array.every()"?

Laravel Get Days In Month From Month Number?

Must be of the type array, null given,

PDOException SQLSTATE[HY000] [2002] No such file or directory

Dynamic dropdown Ajax PHP request

About Contact Privacy policy Terms and conditions