Add exams from exam156 to exam199
This commit is contained in:
35
exam187/customErrorMessage.php
Normal file
35
exam187/customErrorMessage.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?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();
|
||||
}
|
||||
27
exam187/customEx.php
Normal file
27
exam187/customEx.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
// Ovo mi ne radi ne znam iz kog razloga uvek baci error kad pogresim umesto da ispise poruku.
|
||||
$mysql_db = 'example_database';
|
||||
$mysql_host = 'localhosta';
|
||||
$mysql_user = 'example_user';
|
||||
$mysql_pass = 'Kolosnjaj4321!';
|
||||
|
||||
class DatabaseException extends Exception{}
|
||||
class ServerException extends Exception{}
|
||||
|
||||
try{
|
||||
if(!$con = mysqli_connect($mysql_host,$mysql_user,$mysql_pass)){
|
||||
throw new ServerException('Could not connect to server.');
|
||||
} else if (!mysqli_select_db($con,$mysql_db)) {
|
||||
throw new DatabaseException('Could not select database.');
|
||||
} else {
|
||||
echo 'Connected';
|
||||
}
|
||||
|
||||
} catch (ServerException $ex) {
|
||||
echo 'Error: ' . $ex->getMessage();
|
||||
} catch (DatabaseException $ex) {
|
||||
echo 'Error: ' . $ex->getMessage();
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user