Created
September 6, 2011 16:53
-
-
Save satlavida/1198154 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class DB | |
{ | |
public static function __callStatic($name,$args) | |
{ | |
$q= ""; | |
$query = explode("_",$name); | |
if($query[0] == "get") | |
{ | |
$q .= "SELECT * FROM `".$query[1].'`'; | |
if($query[2] == "where") | |
{ | |
$q .= " WHERE ".$query[3]." = ".$args[0]; | |
if($query[4] == "where") | |
{ | |
$q .= " AND WHERE ".$query[5]." = ".$args[1]; | |
} | |
elseif($query[4] == "limit") | |
{ | |
$q .= " LIMIT ".$args[1]; | |
} | |
} | |
} | |
if($query[0] == "find" || $query[0] == "query") | |
{ | |
$q .= $args[0]; | |
} | |
return $q; | |
} | |
} | |
//Example for query maker | |
class Users extends DB{} | |
echo Users::get_users_where_id(1); | |
//Outputs "SELECT * FROM USERS | |
echo "\n"; | |
echo Users::get_users_where_username_where_password('satlavida','mysecret'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment