Archivo de Conexión
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
* Description of MySQLi
*
* @author Lic. Luis Eduardo Alvarez Meneses
*/
class ConectarBD {
//put your code here
private $mysqli;
function __construct() {
$this->conectar();
$this->mbind_types = array();
$this->mbind_params = array();
$this->mbind_types[0] = "";
}
private function conectar() {
//$dato_conn = new Datos();
$this->mysqli = new mysqli("UBICACION BDD", "USUARIO", "CLAVE BDD", "NOMBRE BDD");
if ($this->mysqli->connect_errno) {
return "Falló la conexión a MySQL: (" . $this->mysqli->connect_errno . ") " . $this->mysqli->connect_error;
// exit();
} else {
$this->mysqli->query("SET NAMES 'utf8'");
return "OK";
}
}
/**
* Metodo que reraliza una consulta de tipo select
* @param type $SQL_Select
* @return array
*/
public function query($SQL_Select) {
$data = array();
if (!$resultado = $this->mysqli->query($SQL_Select)) {
return -1;
}
$incremento = 0;
while ($fila = $resultado->fetch_assoc()) {
$data[$incremento] = $fila;
$incremento++;
}
if ($incremento != 0) {
$resultado->free();
$this->mysqli->close();
return $data;
} else {
$resultado->free();
$this->mysqli->close();
return 0;
}
}
/**
* INsert
* Update
* Delete
*
*/
public function execute_query($sql) {
$dato = $this->mysqli->query($sql);
$this->mysqli->close();
return $dato;
}
/**
* Metodo que retona el driver de coneccón la BD MYSQL
* @return type retorna el conector
*/
function getMysqli() {
return $this->mysqli;
}
private $mbind_types = array();
private $mbind_params = array();
public function mbind_param($type, &$param) {
echo $type . " " . $param;
$this->mbind_types[0] .= $type;
$this->mbind_params[] = &$param;
}
function makeValuesReferenced($arr) {
$refs = array();
foreach ($arr as $key => $value)
$refs[$key] = &$arr[$key];
return $refs;
}
private $stmp;
function mbind_param_do() {
$params = array_merge($this->mbind_types, $this->mbind_params);
return call_user_func_array(array($this->stmp, 'bind_param'), $this->makeValuesReferenced($params));
}
public function execute($smpt) {
$this->stmp = $smpt;
print_r($this->mbind_types);
print_r($this->mbind_params);
if (count($this->mbind_params))
$this->mbind_param_do();
return $smpt;
}
}