• 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 create a scheduler application in php

PHP7 CLI attempts to load xdebug twice - "Cannot load Xdebug - it was already loaded"

Why isn't my PHP exception working?

The sum of the user's points

How can I get new CSRF token in LARAVEL by using ajax

Laravel database insert with combining array and string

Create tags in laravel post publishing

Laravel 5.1 Unknown database type enum requested

SQL AVG() to 2 decimals

HTTP Range requests with php for Video Embedding for solving going to specific time in video (seek bar not work)

How to convert a carbon into string, to take the date only?

Warning file_get_contents () failed to open stream: HTTP request failed! HTTP/1.0 402 Payment Required

Saving Data from form to database using AngularJS and php

Uploading video to Youtube using Youtube Data API V3 and Google API Client PHP -- getting 401 (unauthorized) message

How update php.ini on a Mac OS X Mojave?

About Contact Privacy policy Terms and conditions