• 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

Confirm Leave on External Links in Wordpress

Declaration of OMDb::query(string $statement) must be compatible with PDO::query

Why getting "Build step 'Execute shell' marked build as failure" error while creating a backup tar for files

add " ? " in url via htaccess RewriteRule

Check if user online laravel

Can I write PHP code across multiple lines per statement?

Printing more than one array using print_r or any other function in php

HTML and PHP in one file

Target Individual Form Instance/Counter Inside A PHP While Loop

I'm trying to use curl with php but getting this error:Could not resolve host: Bearer

Performance of foreach, array_map with lambda and array_map with static function

How to change the app environment at run time?

Laravel Unresolvable dependency resolving [Parameter #0 [ <required> $method ]] in class GuzzleHttpPsr7Request

Attempt to read property "view" on null when sending password reset email

Select option from dropdown menu with PHP and mySql

About Contact Privacy policy Terms and conditions