• 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

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

Get latest Tweets - What API

Add Class in html Dynamically in PHP

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

How to get median and quartiles/percentiles of an array in JavaScript (or PHP)?

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

Symfony 4: how to allow dynamic values for array nodes in bundle configuration?

How to show selected value using javascript in laravel

Getting output of MS stored procedure on php call

How to give apache permission to write to home directory?

Adding Multiple Custom Post Types in Wordpress

printing all running session variable in laravel 5.1

How to increase the PHP upload limits [duplicate]

Laravel Passport - Not able to get token string in response?

Handle error for duplicate entries - PHP/MySQL

About Contact Privacy policy Terms and conditions