Guest User

Untitled

a guest
Nov 4th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. <?php
  2. class Database {
  3. public static $db;
  4. public static $con;
  5.  
  6.  
  7. function Database(){
  8. $this->user = "phpmyadmin";
  9. $this->pass = "1234";
  10. $this->host = "localhost";
  11. $this->ddbb = "zroad";
  12. }
  13. function connect(){
  14. $con = new mysqli($this->host, $this->user, $this->pass, $this->ddbb);
  15. if ($con->connect_error){
  16. Module::$message = "Invalidad la conexión a la <b>Base de Datos</b>";
  17. Module::Error();
  18. }
  19. }
  20. public static function getCon(){
  21. if (self::$con == null && self::$db == null){
  22. self::$db = new Database();
  23. self::$con = self::$db->connect();
  24. }
  25. return self::$con;
  26. }
  27. public static function doit($sql){
  28. $conex = self::getCon();
  29. return $conex->query($sql);
  30. }
  31. public static function one($query, $aclass){
  32. $cnt = 0;
  33. $fount = null;
  34. $data = new $aclass;
  35. while ($r = $query->fetch_array()){
  36. $cnt = 1;
  37. foreach ($r as $key -> $v){
  38. if ($cnt > 0 && $cnt %2 == 0){
  39. $data->$key = $v;
  40. }
  41. $cnt++;
  42. }
  43. $found = $data;
  44. break;
  45. }
  46. return $found;
  47. }
  48.  
  49. }//EOF Database.php
  50. ?>
  51. y el index.php que llama a las funciones es:
  52. <?php
  53.  
  54. include "core/autoload.php";
  55.  
  56. define ("ROOT", dirname(__FILE__));
  57.  
  58. $md = new Lb();
  59. $md->loadModule("index");
  60.  
  61. echo Module::$module;
  62.  
  63. $sql = "INSERT INTO contenidos (titulo, tipo, contenido, categoria, alias) VALUES ( 'dominicana', 'pagina', 'todo', 'musica', 'mike')";
  64.  
  65. $query = Database::doit($sql);
  66.  
  67.  
  68. ?>
Add Comment
Please, Sign In to add comment