Файл: Space race/classes/connect.class.php
Строк: 72
<?php
/**
* Establish a mySQL connection and select a database.
*
*/
class Connect {
private $error;
public static $dbh;
/**
* Checks if installation is complete by seeing if config.php exists.
*
* The user will be prompted to visit home.php and click "Begin Install" if
* there is no config.php yet setup. This prompt will be persistent and won't
* allow any pages to load until config.php is created.
*
* @return string The error message if an install does not exist.
*/
public function checkInstall() {
if(!file_exists(dirname(__FILE__) . '/config.php')) :
return "<div class='alert alert-warning'>"._('ИГРА НЕ УСТАНОВЛЕНА!')."</div>
<h1>"._('Упс!')."</h1>
<p>"._('Не найден файл конфигурации - config.php.')."</p>
";
endif;
}
/**
* Connect to mySQL and select a database.
*
* The credentials used to connect to the database are pulled from /classes/config.php.
*
* @return string Error message for any incorrect database connection attempts.
*/
public function dbConn() {
include(dirname(__FILE__) . '/config.php');
try {
self::$dbh = new PDO("mysql:host={$host};dbname={$dbName}", $dbUser, $dbPass);
self::$dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING );
} catch (PDOException $e) {
return '<div class="alert alert-danger">'._('Database error: '). $e->getMessage() . '</div>';
}
}
}
// Instantiate the Connect class
$connect = new Connect();