36 lines
870 B
PHP
36 lines
870 B
PHP
<?php
|
|
|
|
$mysql_db = 'example_database';
|
|
$mysql_host = 'localhost';
|
|
$mysql_user = 'example_user';
|
|
$mysql_pass = 'Kolosnjaj4321!';
|
|
|
|
class DatabaseException extends Exception
|
|
{
|
|
public function showSpecific()
|
|
{
|
|
return 'Error thrown on line' . $this->getLine() . ' in ' . $this->getFile();
|
|
}
|
|
}
|
|
class ServerException extends Exception
|
|
{
|
|
public function showSpecific()
|
|
{
|
|
return 'Error thrown on line' . $this->getLine() . ' in ' . $this->getFile();
|
|
}
|
|
}
|
|
|
|
try {
|
|
if (!@$con = mysqli_connect($mysql_host, $mysql_user, $mysql_pass)) {
|
|
throw new ServerException();
|
|
} else if (!@mysqli_select_db($con, $mysql_db)) {
|
|
throw new DatabaseException();
|
|
} else {
|
|
echo 'Connected';
|
|
}
|
|
} catch (ServerException $ex) {
|
|
echo $ex->showSpecific();
|
|
} catch (DatabaseException $ex) {
|
|
echo $ex->showSpecific();
|
|
}
|