Smutty

MVC Framework

View Code: Smutty_Database_MySQL

Browse: All · Classes · Plugins

1
<?php
2
3
/**
4
* an implementation of the database class for MySQL
5
*
6
*/
7
9
10
/** the db connection */
11
var $cnn = null;
12
13
function connect() {
14
$cfg = Smutty_Config::getInstance();
15
$this->cnn = mysql_connect(
16
$cfg->get('db.host'),
17
$cfg->get('db.username'),
18
$cfg->get('db.password')
19
);
20
mysql_select_db( $cfg->get('db.name'), $this->cnn );
21
}
22
23
function query( $sql ) {
24
$res = mysql_query( $sql, $this->cnn );
25
return $res ? new Smutty_Database_MySQL_Result($res) : false;
26
}
27
28
function update( $sql ) {
29
return mysql_query($sql,$this->cnn) ? true : false;
30
}
31
32
function escape( $string ) {
33
$string = preg_replace( '/\\\\/', '\\\\\\\\', $string );
34
$string = preg_replace( '/\'/', '\\\'', $string );
35
return $string;
36
}
37
38
function getInsertId( $table ) {
39
return mysql_insert_id( $this->cnn );
40
}
41
42
function getError() {
43
return mysql_error( $this->cnn );
44
}
45
46
function getCurrentDate() {
47
return date( $this->getDateFormat() . ' h:i:s' );
48
}
49
50
function getFieldsSql( $table ) {
51
return " desc `$table` ";
52
}
53
54
function getDateFormat() {
55
return 'Y-m-d';
56
}
57
58
function script( $file ) {
59
$cfg = Smutty_Config::getInstance();
60
$user = $cfg->get( 'db.username' );
61
$pass = $cfg->get( 'db.password' );
62
$name = $cfg->get( 'db.name' );
63
system( "mysql -u \"$user\" " .
64
" --password=\"$pass\" " .
65
" -D \"$name\" " .
66
" -e \"source $file;\" " );
67
}
68
69
}
70
71
?>

The code shown here is the code that is currently running this site. If you want to view the latest SVN version of the code then go to the Subversion repository.