diff --git a/include/mysql.php b/include/mysql.php index 7ba7036..a4dc61c 100644 --- a/include/mysql.php +++ b/include/mysql.php @@ -1,51 +1,48 @@ link = @mysql_connect($server, $user, $pass) + + function connect($server, $user, $pass, $dbname) { + $this->link = @mysqli_connect($server, $user, $pass, $dbname) or mtdie('Could not connect to the database server.'); - @mysql_select_db($dbname, $this->link) - or mtdie('Could not open the megatokyo database.'); - if( !$this->link ) mtdie('Could not connect to the database server.'); + if( !$this->link ) mtdie('Could not connect to the database server.'); } - function query($sql, $showerror = true ) { - $r = mysql_query( $sql, $this->link ); - if( false === $r && $showerror ) echo mysql_error(); + $r = mysqli_query( $this->link, $sql ); + if( false === $r && $showerror ) echo mysqli_error(); return $r; } - + function getAll($sql) { if( $r = $this->query( $sql ) ) { $ret = array(); - while( $row = mysql_fetch_object( $r ) ) { + while( $row = mysqli_fetch_object( $r ) ) { $ret[] = $row; } return $ret; } } - + function getRow($sql) { if( $r = $this->query( $sql ) ) { if( false === $r ) { - echo mysql_error(); + echo mysqli_error(); return false; } - if( mysql_num_rows( $r ) == 0 ) return false; - return mysql_fetch_object( $r ); + if( mysqli_num_rows( $r ) == 0 ) return false; + return mysqli_fetch_object( $r ); } } - + function getOne($sql) { if( $r = $this->query( $sql ) ) { - if( mysql_num_rows( $r ) == 0 ) return false; - $ret = mysql_fetch_row( $r ); + if( mysqli_num_rows( $r ) == 0 ) return false; + $ret = mysqli_fetch_row( $r ); return $ret[0]; } } } -?> \ No newline at end of file +?>