Zenok Posted September 20, 2012 Report Share Posted September 20, 2012 Hola, les dejo con esta clase MySQL que les permitirá crear su propia CMS con conocimientos básicos sobre php y mysql. Cualquier duda comentar. <!--?php /** * @author Zenok * @page www.metin2zone.net * @copyright Zenok */ class core { public static $string; public function Init() { session_start(); $this->MySQL(); } public function MySQL() { $this->hostname = "localhost"; $this->username = "root"; $this->password = "TU_CONTRASEÑA"; $this->database = "TU_DB"; $this->connection = mysql_connect($this->hostname, $this->username, $this->password) or die(mysql_error()); $this->connection = mysql_select_db($this->database) or die(mysql_error()); return $this->connection; } public function String($string) { $this->String = mysql_real_escape_string($string); $this->String = strip_tags($this->String); return $this->String; } public function User($string) { $this->User = mysql_fetch_assoc(mysql_query("SELECT ".$string." FROM users WHERE id = '".$_SESSION['id']."'")); return $this->User[''.$string.'']; } public function GetOnline() { $this->Online = mysql_fetch_assoc(mysql_query("SELECT users_online FROM server_status")); return $this->Online['users_online']; } } $core = new core(); $core->Init(); ?> - Init(): Inicia la clase PHP - MySQL(): Inicia la conexión MySQL - String(): Filtra las variables para evitar inyecciones SQL - User(): Obtiene la información del usuario - GetOnline(): Obtiene los usuarios conectados en la web 1.- Utilización de la clase Es necesario que al principio de cada archivo se incluya la clase PHP para poder usarla de este modo: <?php require_once("includes/class_core.php"); ?> 2.- Utilización de la clase Para llamar a las funciones en tus códigos php tan solo necesitas realizarlo de este modo: $core->Funcion(); Por ejemplo: Seleccionar dato de usuario por post <?php $username = $core->String($_POST['username']); mysql_query("SELECT id FROM users WHERE username = '$username'"); ?> Recojer usuarios online <?php echo $core->GetOnline(); ?> Pedro Fuentes and cristianvar 2 Quote Link to comment Share on other sites More sharing options...
Pedro Fuentes Posted September 20, 2012 Report Share Posted September 20, 2012 Buena guia! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.