My code is as follows:
conexionbd.php
<?php
$credenciales_bd;
/**Comprueba si el archivo db.php.ini existe*/
if (file_exists("../config/config.php.ini")) {
try{
/*Lee el archivo db.php.ini*/
$credenciales_bd= parse_ini_file('../config/config.php.ini');
/*Obtiene valores del archivo db.php.ini*/
$host= $credenciales_bd['servidor'];
$usuario=$credenciales_bd['user'];
$contrasena=$credenciales_bd['pass'];
$bd=$credenciales_bd['bd'];
/*Crea la conexion MySQL*/
$conn= new mysqli($host,$usuario,$contrasena,$bd);
}catch(Exception $e){
echo '<script>$e</script>';
}
}else{
}
my question is, Can I combine the previous file in a structure of POO
of php
? This is because I want to reuse that code, and use POO
since I have to make several queries MySQL
and would like to have them in functions within the same document.
What I want to do is something like the following:
<?PHP
class Consultas_usuario{
include("conexionbd.php");
$conexion=$conn;
public function consulta1(){
$conexion->query(...);
/*Resto del codigo*/
}
}