• 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

Having trouble with PDO queries (Notice: Undefined index)

Why "Class 'GuzzleHttpClient' not found" even after Installing it in Laravel?

Elasticsearch - Want to sort by field in all indices where that particular field available or not if not then avoid it

WooCommerce Subscriptions: Remove role on cancelled subscription

Insert And Retrieve Data in MySQL with $.post Noob Question

Call authenticate manually in router middleware

PHP Startup: Unable to load dynamic library 'openssl' in Ubuntu

How to average columns of data from multiple, flat arrays?

Insert a DIV after the 6th product only once in WooCommerce category archives

How to disable only_full_group_by option in Laravel

Laravel Delete and Update

How to fix this error : Ask your hosting provider to use PHP 7.2.5 or higher for both HTTP and CLI?

"There is no active transaction" when refreshing database in Laravel 8.0 test

I can't delete my image when it is liked because of the foreign key in mysql

Laravel SQL query midnight time not showing

About Contact Privacy policy Terms and conditions