Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class DataBase{
- protected $dbhost = "localhost";
- protected $dbuser = "fdsf";
- protected $dbname = "dsfdf";
- protected $dbpass = "dsfsd";
- protected $connect = '';
- function __construct() {
- $this->connect = mysql_connect($this->dbhost,$this->dbuser,$this->dbpass) or die(self::MysqlError(mysql_error()));
- mysql_select_db($this->dbname);
- }
- function MysqlError($error){
- echo "<font color=\"red\">Error:</font><small> ".$error."</small>";
- }
- function MysqlQuery($sql) {
- $query = mysql_query($sql) or die(self::MysqlError(mysql_error()));
- return $query;
- }
- function MysqlCount($sql,$identifier) {
- $query = mysql_query($sql) or die(self::MysqlError(mysql_error()));
- $res = mysql_fetch_assoc($query);
- $count = $res['COUNT('.$identifier.')'];
- return $count;
- }
- function MysqlReturn($sql) {
- $query = mysql_query($sql) or die(self::MysqlError(mysql_error()));
- $res = mysql_fetch_array($query);
- return $res;
- }
- function MysqlReturnAll($sql) {
- $query = mysql_query($sql) or die(self::MysqlError(mysql_error()));
- while($r = mysql_fetch_assoc($query)){
- $return[] = $r;
- }
- return $return;
- }
- }
- //Testing script
- $database = new DataBase();
- $user_count = $database->MysqlCount("SELECT COUNT('id') FROM `UserPlay`","'id'");
- $one_user = $database->MysqlReturn("SELECT `id` FROM `UserPlay` ORDER BY rand() LIMIT 1");
- $all_users = $database->MysqlReturnAll("SELECT `id` FROM `UserPlay` ORDER BY `id` ");
- echo "There are ".$user_count." users.<br />";
- echo "Random user: ".$one_user['id']."<br />";
- echo "All users: <table><tr>";
- $i = 0;
- foreach($all_users as $u){
- echo "<td>".$u['id']."</td>";
- $i++;
- if($i%4==0)
- echo "</tr><tr>";
- }
- echo "</tr></table>";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement