• 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

Get Header Authorization value of a login api (sent with username and password in json body) using php curl

SilverStripe unable to populate multiple member Childs

PHP 8.1: strftime() is deprecated

Assets not referencing to public folder (Laravel)

Can I write PHP code across multiple lines per statement?

How to get quarter for future date using Carbon?

How to fix " Uncaught TypeError: Argument 1 passed to JpGraphException::defaultHandler() " problem in php 7.1.3 and jpgraph 4.2.6?

WAMP/Wordpress - cURL error 28: Operation timed out after 10001 milliseconds with 0 bytes received

How to MODIFY a Google Docs document via API using search-and-replace?

How to convert the int value to inch in PHP [closed]

Comma separated list from array with "and" before last element

SQL AVG() to 2 decimals

Send POST data via raw JSON with Postman

Laravel multi auth - Authentication user provider [] is not defined

how to use extended ASCII instead of unicode in PHP

About Contact Privacy policy Terms and conditions