• 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

Unable to get password for the instance created from AMI

Malformed MIME header error in Symfony 5.3

Sentry on Symfony: how to exclude `NotFoundHttpException`

add " ? " in url via htaccess RewriteRule

SMTP ERROR: MAIL FROM command failed: 530 5.7.0 Must issue a STARTTLS command first when using PHPMailer

Having issue with matching rows in the database using PDO

GuzzleHttp Hangs When Using Localhost

How to use $this->session->set_userdata in codeigniter

Yoast SEO (WordPress Plugin) - Get plugin generated data manually

renameColumn migration fails for existing column with columns does not exist error

codeigniter 4 running error first time with xampp

Call to a member function fetch_field() on a non-object MySQLiDB

How to run a shell as root from php (apache)

"Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP

Laravel SQL query midnight time not showing

About Contact Privacy policy Terms and conditions