Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class database {
- var $link, $result;
- function database($host, $user, $pass, $db) {
- $this->link = mysql_connect($host, $user, $pass) or $this->error();
- mysql_select_db($db, $this->link) or $this->error();
- }
- function query($query) {
- $this->result = mysql_query($query, $this->link) or $this->error();
- $this->_query_count++;
- return $this->result;
- }
- function countRows($result = "") {
- if ( empty( $result ) )
- $result = $this->result;
- return mysql_num_rows($result);
- }
- function fetch($result = "") {
- if ( empty( $result ) )
- $result = $this->result;
- return mysql_fetch_array($result);
- }
- function fetch_num($result = "") {
- if ( empty( $result ) )
- $result = $this->result;
- return mysql_fetch_array($result, MYSQL_NUM);
- }
- function fetch_assoc($result = "") {
- if ( empty( $result ) )
- $result = $this->result;
- return mysql_fetch_array($result, MYSQL_ASSOC);
- }
- function escape($str) {
- return mysql_real_escape_string($str);
- }
- function error() {
- if ( $_GET["debug"] == 0 ){
- die(mysql_error());
- } else {
- echo "Error in db code";
- }
- }
- }
- function sanitize($data) {
- // apply stripslashes if magic_quotes_gpc is enabled
- if(get_magic_quotes_gpc())
- $data = stripslashes($data);
- // a mySQL connection is required before using this function
- $data = trim(mysql_real_escape_string($data));
- return $data;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement