• 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

Fatal error: Uncaught mysqli_sql_exception: Unknown database 'test' in ... (How do I fix that? Using PHP)

Applying programmatically a coupon to an Order in WooCommerce3

Must be of the type array, null given,

Center point of multiple gps coordinates with php

How to pass data to all views in Laravel 5?

php - add comma thousands separator but remove trailing zeros

Form Validation and Submission to database

php curl_exec() Connection refused when retrieving a remote image

Error Class "LaravelFortifyFeatures" not found

RuntimeException: Unable to create the cache directory (/var/www/sonata/app/cache/dev)

Nginx RTMP not recording

CodeIgniter 4: Like and Dislike Functionality

Check if user online laravel

Uncaught TypeError: Cannot read property 'length' of null when retrieving tags from wp

SQL AVG() to 2 decimals

About Contact Privacy policy Terms and conditions