• 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

Prestashop webservice API creating cart rules

how to search for a file with php

Split array into 4-element chunks then implode into strings

Converting IPv6 to IPv4 address in PHP

Refresh specific HTML content that retrieves data from MySQL

Laravel Mix Uncaught ReferenceError: $ is not defined

Doctrine 2 mapping referencing unique key

Do I need to install `fxp/composer-asset-plugin` if I'm not doing front-end development

Using spatie/media-library, how to rename a collection of uploaded files?

Chunk and transpose a flat array into rows with a specific number of columns

Pagekite error: FAIL: localhost:8080 is down

Exact alternate to mcrypt_encrypt in PHP 7.2

How do I loop through an MS SQL database with VB.NET?

Send same name multiple checkbox values via ajax

Make certain characters of a word from string bold

About Contact Privacy policy Terms and conditions