Advertisement
Guest User

Untitled

a guest
Aug 18th, 2016
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. <?php
  2.  
  3. $host = '127.0.0.1';
  4. $db = 'test';
  5. $user = 'root';
  6. $pass = 'blah';
  7. $charset = 'utf8';
  8.  
  9. $dsn = "mysql:host=$host;dbname=$db;charset=$charset"; // data source name
  10. $dbh = new PDO("$dsn", $user, $pass)
  11.  
  12. function create_db() {
  13. try {
  14. $dbh->exec("CREATE DATABASE `$db`;") or die(print_r($dbh->errorInfo(), true));
  15. } catch (PDOException $e) {
  16. die("DB ERROR: " . $e->getMessage());
  17. }
  18. return 0;
  19. }
  20.  
  21. create_db();
  22.  
  23. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement