-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnect.inc
43 lines (38 loc) · 932 Bytes
/
connect.inc
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
<?php
$dbhost = 'host';
$dbport = '3306';
$dbusername = 'root';
$dbpassword = 'password';
$dbdatabase = 'invoices';
$username = 'username';
$password = 'password';
//mysql_connect($dbhost.':'.$dbport, $dbusername, $dbpassword) or die ("<h1>Server unreachable</h1>");
//mysql_select_db($dbdatabase) or die ("<h1>cannot connect to database</h1>");
try{
$db = new PDO("mysql:host={$dbhost};port={$dbport};dbname={$dbdatabase}", $dbusername, $dbpassword, array(PDO::ATTR_PERSISTENT => true));
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
exit;
}
function check_input($value)
{
global $db;
if (get_magic_quotes_gpc())
{
$value = stripslashes($value);
}
$value = $db->quote($value);
if(preg_match("/^\'(.*)\'$/s", $value))
{
return substr($value, 1, strlen($value) - 2);
}
else
{
return $value;
}
}
foreach($_REQUEST as $key => $value)
{
$_REQUEST[$key] = check_input($value);
}
?>