Register for your free account! | Forgot your password?

Go Back   elitepvpers › Coders Den › Web Development
You last visited: Today at 06:12

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[PHP]Dynamic Database Framework

Discussion on [PHP]Dynamic Database Framework within the Web Development forum part of the Coders Den category.

Reply
 
Old   #1
 
x[t]c's Avatar
 
elite*gold: 0
Join Date: Mar 2009
Posts: 34
Received Thanks: 6
[PHP]Dynamic Database Framework

Currently working on a dynamic database framework for MySql. If you have any suggestions for me please share

index.php
Code:
<?php
require_once("incs/database.php");
$accounts = Database::Accounts();
echo $accounts->getUserId("username", "[PM]Example");
?>
database.php
Code:
<?php
define("WORKING_DIRECTORY", getcwd());
include_once(WORKING_DIRECTORY."\\incs\\settings.php");

class Database
{
	protected $tableName = "table";
	protected $connection;
	protected $database;
	public function __construct()
	{
		$this->tableName = strtolower(get_class($this));
		$this->connection = mysqli_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS);
		$this->database = mysqli_select_db($this->connection, MYSQL_DB);
	}
	public function __call($name, $arguments)
	{
		$opt = strtolower(substr($name, 0, 3));
		switch($opt)
		{
			case "get":
				{
					$col = strtolower(substr($name, 3, strlen($name)));
					$where = mysqli_real_escape_string($this->connection, $arguments[0]);
					$equals = mysqli_real_escape_string($this->connection, $arguments[1]);
					$query = mysqli_query($this->connection, "SELECT `".$col."` FROM `".$this->tableName."` WHERE `".$where."`='".$equals."' LIMIT 1");
					$query = mysqli_fetch_assoc($query);
					return $query[$col];
				}
			case "set":
				{
					$col = strtolower(substr($name, 3, strlen($name)));
					$val = mysqli_real_escape_string($this->connection, $arguments[0]);
					$where = mysqli_real_escape_string($this->connection, $arguments[1]);
					$equals = mysqli_real_escape_string($this->connection, $arguments[2]);
					return mysqli_query($this->connection, "UPDATE `".$this->tableName."` SET `".$col."`='".$val."' WHERE `".$where."`='".$equals."'");
				}
			default:
				{
					throw new Exception("Tried to use __call without using a get/set in database.php");
					break;
				}
		}
	}
	public static function __callStatic($name, $arguments)
	{
		$className = strtolower($name);
		$con = mysqli_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS);
		$db = mysqli_select_db($con, MYSQL_DB);
		if (mysqli_query($con, "DESCRIBE ".$className))
		{
			$path = WORKING_DIRECTORY."\\incs\\".$className.".php";
			if (!file_exists($path))
			{
				$code = "class $className extends Database { }";
				eval($code);
			}
		} else {
			throw new Exception("Table with the name ".$className." does not exist.");
		}
		return new $className();
	}
	public function query($query)
	{
		return mysqli_query($this->connection, $query);
	}
	public function fetch_assoc($query)
	{
		return mysqli_fetch_assoc($query);
	}
	public function num_rows($query)
	{
		return mysqli_num_rows($query);
	}
	public function __sleep()
	{
		mysqli_close($this->connection);
	}
}
?>
settings.php
Code:
<?php
define("MYSQL_HOST", "localhost");
define("MYSQL_USER", "root");
define("MYSQL_PASS", "root");
define("MYSQL_DB", "test");
?>
x[t]c is offline  
Reply


Similar Threads Similar Threads
[Official Release] Rainbow Database: Vampire/Godship/Legionairre Database!
04/25/2021 - EO PServer Guides & Releases - 106 Replies
http://i43.tinypic.com/jgo485.png Additional: The database contains all material and server features which I alone coded, designed and created. I can barely recall if their were any bugs. I think there was with one of the vampire skills. People said it was supposed to be an xp skill but they could use it without having to be on XP. So its pretty minor but if you find any other problems please report them to this thread and i'll make a fix asap. Many database releases have come before this...
[Release] Sro-r DataBase , And Real TWsro DataBase
04/01/2013 - SRO Private Server - 10 Replies
its a gift from me because i will left Sro Forever so today i will release Sro-r DataBase , And Real Twsro Database + Server Files Download Link HAPPY 1/4 :D i never do that lol you mad ! ? :p
Dynamic Ip
05/15/2012 - SRO Private Server - 2 Replies
Hello i found 2 good private servers have vote 4 silk system but both have problem in this point 1-Dymer Online 2-GoodTimes you guys must stop this system this will ruin your server very fast cuz ppl who have Dynamic ip in there router will keep restart the modem and get another ip so he/she can vote again and get more silk oh and this dynamic ip is undefeatable in Dymer server i could get like 500 silk per 10 minutes oh and one more thing



All times are GMT +1. The time now is 06:12.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.