-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsql.php
52 lines (43 loc) · 1.06 KB
/
sql.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
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
<?php
function select($sql){
require 'config/database.php';
try
{
$db = new PDO($DB_DSN.";dbname=Camagru", $DB_USER, $DB_PASSWORD);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (Exceptions $e)
{
echo $sql . "\n" . $e->getMessage();
}
//echo $sql.PHP_EOL;
$sth = $db->prepare($sql);
$sth->execute();
$arr = $sth->fetchAll(PDO::FETCH_ASSOC);
return $arr;
}
function insert($sql){
require 'config/database.php';
try
{
$db = new PDO($DB_DSN.";dbname=Camagru", $DB_USER, $DB_PASSWORD);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (Exceptions $e)
{
echo $sql . "\n" . $e->getMessage();
}
$db->exec($sql);
}
function html_tab($array){
echo '<table cellpadding="10">' ;
foreach ($array as $k => $v) {
echo '<tr><td>'.$k.'</td><td>' . $v . '</td></tr>' ;
}
echo '</table>' ;
}
function console($req){
$req = addslashes($req);
echo "<script>console.log('$req')</script>";
}
?>