• 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 to map the two arrays with a duplicate value?

In PHP, which is faster: preg_split or explode?

How to run a shell as root from php (apache)

XDebug not working in VScode for php debugging

Laravel lang slug in url

How to KeyBy where multiple items have the same key

How to display MySQL table using php and edit it in a web browser

Too few arguments to function PendingResourceRegistration::name(),1 passed in C:xampphtdocsproject outesweb.php on line 18 and exactly 2 expected

PHP my timezone is no setting up in PHP.ini File in xampp

How to skip cart page on woocomerce for certain products only?

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

Getting values for an enum?

Sort multidimensional array by column value within a column

Update Order custom Field value with WooCommerce REST API

Json_Encode not returning html even i try to encode JSON_HEX_QUOT | JSON_HEX_TAG

About Contact Privacy policy Terms and conditions