debug){ echo ''."En constructor clase conexion".''; } $listadatos = $this->datosConexion(); foreach ($listadatos as $key => $value) { $this->server = $value['server']; $this->user = $value['user']; $this->password = $value['password']; $this->database = $value['database']; $this->port = $value['port']; } if ($this->debug){ echo "datos constructor: SERVER: $this->server, USER: $this->user, PASS: $this->password, DB: $this->database, PORT: $this->port".'';} if ($this->debug){ echo ''."pre conector".''; } try { $conn = new mysqli("$this->server","$this->user","$this->password","$this->database","$this->port"); $this->conector = $conn; if ($this->debug){ echo "todo BIEN con la conexion"; } } catch (Exception $e) { echo ''."Error al intentar conectar con base de datos!".''; echo "connect_errno: [$conn->connect_errno]".''; echo "connect_error: [$conn->connect_error]".''; echo "Exception: $e".''; die(); } if ($this->debug){ echo ''."post conector".''; } } private function datosConexion(){ if ($this->debug){ echo ''."En funcion datosConexion".''; } $ruta = dirname(__FILE__); $jsondata = file_get_contents($ruta . "/" . "config"); if ($this->debug){ echo ''."Ruta: $ruta".''.'
'; print_r($jsondata); echo ''.''; } return json_decode($jsondata, true); } private function convertirUTF8($array){ if ($this->debug){ echo ''."En funcion convertirUTF8".''; } array_walk_recursive($array,function(&$item,$key){ if(!mb_detect_encoding($item,'utf-8',true)){ $item = utf8_encode($item); } }); return $array; } public function obtenerDatos($query){ if ($this->debug){ echo ''."En funcion obtenerDatos".''; } $results = $this->conector->query($query); $resultsArray = array(); foreach ($results as $value) { $resultsArray[] = $value; } if ($this->debug){ echo '
'; print_r($resultsArray); echo ''.''; } return $this->convertirUTF8($resultsArray); } public function test_conector(){ echo ''."Funcion test_conector".''; } public function nonQuery($sqlstr){ $results = $this->conector->query($sqlstr); #return $results->affected_rows; return $this->conector->affected_rows; } // INSERT public function nonQueryId($sqlstr){ $results = $this->conector->query($sqlstr); $filas = $this->conector->affected_rows; if ($filas >= 1){ #return $results->insert_id; return $this->conector->insert_id; } else { return 0; } } } ?>