• 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 can I remove the "Advanced" panel of all blocks in WordPress block editor?

php code to send checkbox form results to email

Laravel 8 factory state afterCreating

Assets not referencing to public folder (Laravel)

Transfer data between JavaScript and PHP through JSON

Laravel - Browser displays message again when I press back button

Laravel query builder binding parameters more than once

Laravel 5.2: Unable to locate factory with name [default]

if statement inside concatenation

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'posts.post' doesn't exist

How to install PHP composer inside a docker container

Check if user online laravel

How to debug in WooCommerce 3+

Respond with status code 401 on authentication failure using Laravel and Passport?

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

About Contact Privacy policy Terms and conditions