Guest User

Untitled

a guest
May 31st, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. <?php
  2. public function database_init($connection_type,$database,$pdo_options=array()){
  3. $user = "";
  4. $pass = "";
  5. // Correct any possible issues that may have occured.
  6. $connection_type = strval($connection_type);
  7. // Check to make sure database driver is available
  8. if(in_array( $connection_type,PDO::getAvailableDrivers())){
  9. // Now we check to see what type of driver is usable now
  10. switch($connection_type){
  11. case 'mysql':
  12. break;
  13. // Our default and only properly handled option is SQLite (sorry if you wanted mysql)
  14. case 'sqlite':
  15. default:
  16. $database_driver = 'sqlite';
  17. break;
  18. }
  19. } else {
  20. print "Driver Failure";
  21. //throw new DatabaseDriverFailure("Databse does not exist");
  22. // Error Occured {Error handler should probably impliment}
  23. } // End the Checks
  24. // Attempt to connect
  25. try {
  26. $connector = $database_driver.":";
  27. if(!is_array( $pdo_options )){
  28. $pdo_options = array(
  29. PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
  30. );
  31. }
  32. if(file_exists($database)){
  33. $connector .= $database;
  34. } else {
  35. print "File Failure";
  36. }
  37. parent::__construct($connector,$user,$pass,$pdo_options);
  38. } catch ( PDOexception $e ){
  39. print "PDO Failure $e";
  40. }
  41. }
  42. ?>
Add Comment
Please, Sign In to add comment