Not Reviewed
Show More
Add another comment
| @@ -1,51 +1,48 | |||
|
|
1 | 1 | <?php |
|
|
2 | 2 | |
|
|
3 | ||
|
|
4 | 3 | class MysqlStore { |
|
|
5 | 4 | var $link; |
|
|
6 | function connect($server,$user,$pass,$dbname) { | |
|
|
7 |
|
|
|
|
5 | ||
|
|
6 | function connect($server, $user, $pass, $dbname) { | |
|
|
7 | $this->link = @mysqli_connect($server, $user, $pass, $dbname) | |
|
|
8 | 8 | or mtdie('Could not connect to the database server.'); |
|
|
9 | @mysql_select_db($dbname, $this->link) | |
|
|
10 | or mtdie('Could not open the megatokyo database.'); | |
|
|
11 | if( !$this->link ) mtdie('Could not connect to the database server.'); | |
|
|
9 | if( !$this->link ) mtdie('Could not connect to the database server.'); | |
|
|
12 | 10 | } |
|
|
13 | 11 | |
|
|
14 | ||
|
|
15 | 12 | function query($sql, $showerror = true ) { |
|
|
16 |
$r = mysql_query( |
|
|
|
17 | if( false === $r && $showerror ) echo mysql_error(); | |
|
|
13 | $r = mysqli_query( $this->link, $sql ); | |
|
|
14 | if( false === $r && $showerror ) echo mysqli_error(); | |
|
|
18 | 15 | return $r; |
|
|
19 | 16 | } |
|
|
20 | ||
|
|
17 | ||
|
|
21 | 18 | function getAll($sql) { |
|
|
22 | 19 | if( $r = $this->query( $sql ) ) { |
|
|
23 | 20 | $ret = array(); |
|
|
24 | while( $row = mysql_fetch_object( $r ) ) { | |
|
|
21 | while( $row = mysqli_fetch_object( $r ) ) { | |
|
|
25 | 22 | $ret[] = $row; |
|
|
26 | 23 | } |
|
|
27 | 24 | return $ret; |
|
|
28 | 25 | } |
|
|
29 | 26 | } |
|
|
30 | ||
|
|
27 | ||
|
|
31 | 28 | function getRow($sql) { |
|
|
32 | 29 | if( $r = $this->query( $sql ) ) { |
|
|
33 | 30 | if( false === $r ) { |
|
|
34 | echo mysql_error(); | |
|
|
31 | echo mysqli_error(); | |
|
|
35 | 32 | return false; |
|
|
36 | 33 | } |
|
|
37 | if( mysql_num_rows( $r ) == 0 ) return false; | |
|
|
38 | return mysql_fetch_object( $r ); | |
|
|
34 | if( mysqli_num_rows( $r ) == 0 ) return false; | |
|
|
35 | return mysqli_fetch_object( $r ); | |
|
|
39 | 36 | } |
|
|
40 | 37 | } |
|
|
41 | ||
|
|
38 | ||
|
|
42 | 39 | function getOne($sql) { |
|
|
43 | 40 | if( $r = $this->query( $sql ) ) { |
|
|
44 | if( mysql_num_rows( $r ) == 0 ) return false; | |
|
|
45 | $ret = mysql_fetch_row( $r ); | |
|
|
41 | if( mysqli_num_rows( $r ) == 0 ) return false; | |
|
|
42 | $ret = mysqli_fetch_row( $r ); | |
|
|
46 | 43 | return $ret[0]; |
|
|
47 | 44 | } |
|
|
48 | 45 | } |
|
|
49 | 46 | } |
|
|
50 | 47 | |
|
|
51 | ?> No newline at end of file | |
|
|
48 | ?> | |
Comments 0
You need to be logged in to leave comments.
Login now
