forked from rothkj1022/php-error-handler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.php
More file actions
70 lines (54 loc) · 1.84 KB
/
example.php
File metadata and controls
70 lines (54 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
require('vendor/autoload.php');
require('src/PHPErrorHandler.php');
$cacheFolder = dirname(__FILE__).'/tmp/';
// contants for testing
define('ENVIRONMENT', 'development'); // development, testing or production
define('FS_CACHE', $cacheFolder);
define('DB_HOSTNAME', 'localhost');
define('DB_USERNAME', 'localdev');
define('DB_PASSWORD', '7bhyGvtjmT5a');
define('DB_DATABASE', 'test');
define('DB_PORT', 3306);
define('DB_CHARSET', 'utf8');
// set timezone
date_default_timezone_set("America/Chicago");
//INSTANTIATE ERROR HANDLER
use rothkj1022\PHPErrorHandler;
$errorHandlerConfig = (require('example.config.php')); //EDIT THIS FILE
$errorHandler = new PHPErrorHandler\PHPErrorHandler($errorHandlerConfig);
// TRIGGER SOME ERRORS
// trigger fatal error
trigger_error("Custom user fatal error", E_USER_ERROR);
// trigger warning
trigger_error("Custom user warning", E_USER_WARNING);
// trigger notice
trigger_error("Custom user notice", E_USER_NOTICE);
//trigger deprecated
trigger_error("Custom user deprecated message", E_USER_DEPRECATED);
// undefined variable
print_r($arra);
// No such file or directory
include_once 'file.php';
// division by zero
$i = 5 / 0;
// failed to open stream: No such file or directory
$file=fopen("welcome.txt","r");
if (!isset($myVar)) {
$errorHandler->sendError('$myVar is not defined.', 'You should really define that variable.', __FILE__, __LINE__);
}
// trigger a mysql error
if (!isset($mysqli)) {
$mysqli = new mysqli(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE, DB_PORT);
$mysqli->set_charset(DB_CHARSET);
}
if ($mysqli) {
$sql = "select blah from products limit 3";
$query = $mysqli->query($sql) or $errorHandler->mysqlError($mysqli->error, $sql, __FILE__, __LINE__);
if ($query->num_rows > 0) {
while ($row = $query->fetch_assoc()) {
echo '<p>'.$result['prodfull'].'</p>'."\n";
}
}
$query->close();
}