-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdb.php
43 lines (34 loc) · 873 Bytes
/
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
<?php
function db_link()
{
$config = parse_ini_file('config.ini.php');
$link = mysql_connect($config['mysql_host'], $config['mysql_user'], $config['mysql_password']);
if ($link !== false) {
if (mysql_select_db($config['mysql_dbname']) === false) {
mysql_close($link);
$link = false;
}
}
return $link;
}
function db_query($query)
{
$res = mysql_query($query, db_link());
if ($res === false) {
echo mysql_errno() . ': ' . mysql_error() . '<br />';
}
return $res;
}
/*function select($table, $fields=null, $where=null, $limit=null)
{
if (is_null($fields)) {
$fields = '*';
}
$res = db_query("SELECT ");
}*/
function db_insert($table, $fields)
{
$sql = "INSERT INTO `$table` (`" . implode('`,`', array_keys($fields)) . "`) VALUES('" . implode('\',\'', array_map('addslashes', $fields)) . "');";
db_query($sql);
return mysql_insert_id();
}