-
Notifications
You must be signed in to change notification settings - Fork 5
/
db.php
80 lines (75 loc) · 2.55 KB
/
db.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
if(class_exists('MySqlUtil') != true)
{
class MySqlUtil
{
public function __construct()
{
}
public function query($sql, $params)
{
$result = array();
/*
$link = mysql_connect ( SAE_MYSQL_HOST_M . ':' . SAE_MYSQL_PORT, SAE_MYSQL_USER, SAE_MYSQL_PASS );
mysql_select_db ( SAE_MYSQL_DB, $link );
mysql_set_charset("utf8");
$query = mysql_query ( $sql );
while ( $row = mysql_fetch_array ( $query, MYSQL_ASSOC ) ) {
$result[] = $row;
}
mysql_free_result ( $query );
mysql_close( $link );
*/
$dsn = 'mysql:host=' . SAE_MYSQL_HOST_M . ';port=' . SAE_MYSQL_PORT . ';dbname=' . SAE_MYSQL_DB;
$ops = array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8");
$pdo = new PDO($dsn, SAE_MYSQL_USER, SAE_MYSQL_PASS, $ops);
$pre = $pdo->prepare($sql);
$pre->execute($params);
$query = $pre->fetchAll();
foreach ($query as $row) {
$result[] = $row;
}
$pdo = null;
return $result;
}
public function insert($sql, $params)
{
$id = -1;
/*
$link = mysql_connect ( SAE_MYSQL_HOST_M . ':' . SAE_MYSQL_PORT, SAE_MYSQL_USER, SAE_MYSQL_PASS );
mysql_select_db ( SAE_MYSQL_DB, $link );
mysql_set_charset("utf8");
$query = mysql_query ( $sql );
if($query){
$id = mysql_insert_id();
}
mysql_close( $link );
*/
$dsn = 'mysql:host=' . SAE_MYSQL_HOST_M . ';port=' . SAE_MYSQL_PORT . ';dbname=' . SAE_MYSQL_DB;
$ops = array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8");
$pdo = new PDO($dsn, SAE_MYSQL_USER, SAE_MYSQL_PASS, $ops);
$pre = $pdo->prepare($sql);
$pre->execute($params);
$id = $pdo->lastInsertId();
return $id;
}
public function excute($sql, $params)
{
/*
$link = mysql_connect ( SAE_MYSQL_HOST_M . ':' . SAE_MYSQL_PORT, SAE_MYSQL_USER, SAE_MYSQL_PASS );
mysql_select_db ( SAE_MYSQL_DB, $link );
mysql_set_charset("utf8");
$query = mysql_query ( $sql );
mysql_close( $link );
*/
$dsn = 'mysql:host=' . SAE_MYSQL_HOST_M . ';port=' . SAE_MYSQL_PORT . ';dbname=' . SAE_MYSQL_DB;
$ops = array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8");
$pdo = new PDO($dsn, SAE_MYSQL_USER, SAE_MYSQL_PASS, $ops);
$pre = $pdo->prepare($sql);
$pre->execute($params);
$count = $pre->rowCount();
return $count;
}
}
}
?>