Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Database {
- public static $db;
- public static $con;
- function Database(){
- $this->user = "phpmyadmin";
- $this->pass = "1234";
- $this->host = "localhost";
- $this->ddbb = "zroad";
- }
- function connect(){
- $con = new mysqli($this->host, $this->user, $this->pass, $this->ddbb);
- if ($con->connect_error){
- Module::$message = "Invalidad la conexión a la <b>Base de Datos</b>";
- Module::Error();
- }
- }
- public static function getCon(){
- if (self::$con == null && self::$db == null){
- self::$db = new Database();
- self::$con = self::$db->connect();
- }
- return self::$con;
- }
- public static function doit($sql){
- $conex = self::getCon();
- return $conex->query($sql);
- }
- public static function one($query, $aclass){
- $cnt = 0;
- $fount = null;
- $data = new $aclass;
- while ($r = $query->fetch_array()){
- $cnt = 1;
- foreach ($r as $key -> $v){
- if ($cnt > 0 && $cnt %2 == 0){
- $data->$key = $v;
- }
- $cnt++;
- }
- $found = $data;
- break;
- }
- return $found;
- }
- }//EOF Database.php
- ?>
- y el index.php que llama a las funciones es:
- <?php
- include "core/autoload.php";
- define ("ROOT", dirname(__FILE__));
- $md = new Lb();
- $md->loadModule("index");
- echo Module::$module;
- $sql = "INSERT INTO contenidos (titulo, tipo, contenido, categoria, alias) VALUES ( 'dominicana', 'pagina', 'todo', 'musica', 'mike')";
- $query = Database::doit($sql);
- ?>
Add Comment
Please, Sign In to add comment