SHARE
TWEET

Untitled

a guest Oct 3rd, 2017 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. class DataBase{
  3.    
  4.     protected $dbhost = "localhost";
  5.     protected $dbuser = "fdsf";
  6.     protected $dbname = "dsfdf";
  7.     protected $dbpass = "dsfsd";
  8.     protected $connect = '';
  9.    
  10.     function __construct() {
  11.         $this->connect = mysql_connect($this->dbhost,$this->dbuser,$this->dbpass) or die(self::MysqlError(mysql_error()));
  12.         mysql_select_db($this->dbname);
  13.     }  
  14.    
  15.     function MysqlError($error){
  16.         echo "<font color=\"red\">Error:</font><small> ".$error."</small>";
  17.     }
  18.    
  19.     function MysqlQuery($sql) {
  20.         $query = mysql_query($sql) or die(self::MysqlError(mysql_error()));
  21.         return $query;
  22.     }
  23.    
  24.     function MysqlCount($sql,$identifier) {
  25.         $query = mysql_query($sql) or die(self::MysqlError(mysql_error()));
  26.         $res = mysql_fetch_assoc($query);
  27.         $count = $res['COUNT('.$identifier.')'];
  28.         return $count;
  29.     }
  30.    
  31.     function MysqlReturn($sql) {
  32.         $query = mysql_query($sql) or die(self::MysqlError(mysql_error()));
  33.         $res = mysql_fetch_array($query);
  34.         return $res;
  35.     }
  36.    
  37.     function MysqlReturnAll($sql) {
  38.         $query = mysql_query($sql) or die(self::MysqlError(mysql_error()));
  39.         while($r = mysql_fetch_assoc($query)){
  40.             $return[] = $r;
  41.         }
  42.         return $return;
  43.     }
  44. }
  45.  
  46. //Testing script
  47. $database = new DataBase();
  48. $user_count = $database->MysqlCount("SELECT COUNT('id') FROM `UserPlay`","'id'");
  49. $one_user = $database->MysqlReturn("SELECT `id` FROM `UserPlay` ORDER BY rand() LIMIT 1");
  50. $all_users = $database->MysqlReturnAll("SELECT `id` FROM `UserPlay` ORDER BY `id` ");
  51. echo "There are ".$user_count." users.<br />";
  52. echo "Random user: ".$one_user['id']."<br />";
  53. echo "All users: <table><tr>";
  54.     $i = 0;
  55.     foreach($all_users as $u){
  56.         echo "<td>".$u['id']."</td>";
  57.         $i++;
  58.         if($i%4==0)
  59.             echo "</tr><tr>";
  60.     }
  61. echo "</tr></table>";
  62. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top