Swiftriver\Core\Modules\DataContext\MySql_V2\DataContext::PDOConnection PHP Method

PDOConnection() public static method

Generic function used to gain a new PDO connection to the database.
public static PDOConnection ( ) : PDO
return PDO
    public static function PDOConnection()
    {
        $databaseUrl = (string) Setup::$Configuration->DataBaseUrl;
        $databaseName = (string) Setup::$Configuration->Database;
        $connectionString = "mysql:host={$databaseUrl};dbname={$databaseName}";
        $username = (string) Setup::$Configuration->UserName;
        $password = (string) Setup::$Configuration->Password;
        $pdo = new \PDO($connectionString, $username, $password);
        return $pdo;
    }

Usage Example

 /**
  * This function returns an initilised \PDO object that
  * can be used by the calling class to access the data
  * store. The implementation of generating the \PDO
  * object is switched on the DataContentType property
  * of the $request parameter
  * 
  * @param \Swiftriver\Core\Analytics\AnalyticsRequest $request
  * @return \PDO
  */
 public function PDOConnection($request)
 {
     switch ($request->DataContextType) {
         case "\\Swiftriver\\Core\\Modules\\DataContext\\MySql_V2\\DataContext":
             return \Swiftriver\Core\Modules\DataContext\MySql_V2\DataContext::PDOConnection();
         default:
             return null;
     }
 }
All Usage Examples Of Swiftriver\Core\Modules\DataContext\MySql_V2\DataContext::PDOConnection