Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- public function database_init($connection_type,$database,$pdo_options=array()){
- $user = "";
- $pass = "";
- // Correct any possible issues that may have occured.
- $connection_type = strval($connection_type);
- // Check to make sure database driver is available
- if(in_array( $connection_type,PDO::getAvailableDrivers())){
- // Now we check to see what type of driver is usable now
- switch($connection_type){
- case 'mysql':
- break;
- // Our default and only properly handled option is SQLite (sorry if you wanted mysql)
- case 'sqlite':
- default:
- $database_driver = 'sqlite';
- break;
- }
- } else {
- print "Driver Failure";
- //throw new DatabaseDriverFailure("Databse does not exist");
- // Error Occured {Error handler should probably impliment}
- } // End the Checks
- // Attempt to connect
- try {
- $connector = $database_driver.":";
- if(!is_array( $pdo_options )){
- $pdo_options = array(
- PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
- );
- }
- if(file_exists($database)){
- $connector .= $database;
- } else {
- print "File Failure";
- }
- parent::__construct($connector,$user,$pass,$pdo_options);
- } catch ( PDOexception $e ){
- print "PDO Failure $e";
- }
- }
- ?>
Add Comment
Please, Sign In to add comment