-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnect.php
27 lines (20 loc) · 983 Bytes
/
connect.php
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
<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 'On'); //On or Off
try {
$db_host = 'localhost'; // hostname
$db_name = 'dbname'; // databasename
$db_user = 'yo_so_cool'; // username
$user_pw = 'somerealcoolpassword'; // password
$con = new PDO('mysql:host='.$db_host.'; dbname='.$db_name, $db_user, $user_pw);
$con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$con->exec("SET CHARACTER SET utf8"); // return all sql requests as UTF-8
}
catch (PDOException $err) {
echo "harmless error message if the connection fails";
$err->getMessage() . "<br/>";
file_put_contents('PDOErrors.txt',$err, FILE_APPEND); // write some details to an error-log outside public_html
die(); // terminate connection
}
//
?>