note 106842 deleted from function.mysql-connect by danbrown
| From: | danbrown@php.net | Date: | Sun, 11 Dec 2011 19:19:45 +0000 |
| Subject: | note 106842 deleted from function.mysql-connect by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-185048@lists.php.net to get a copy of this message | ||
Note Submitter: nikonikoydx at hotmail dot com
----
<?php
class Connection
{
private $connection;
private $hostname;
private $port;
private $username;
private $password;
private $database;
/**
* Metodo para abrir la conexion con el servicio de MySql PHP
* @return the $connection openned
*/
public function OpenMySQLConnection()
{
$this->hostname = "localhost";
$this->username = "root"; // only example
$this->password = "root"; // only example
$this->database = "name_database";
$this->connection = (mysql_connect($this->hostname, $this->username,
$this->password));
if(!($this->connection))
{
die('ERROR CONNECTION:<br/>Error al conectarse con la Base de Datos:
'.mysql_error()."<br/>DETALLE ERROR:<br/>".mysql_error());
exit();
return false;
}
else
{
if(!(mysql_select_db($this->database, $this->connection)))
{
die('ERROR SELECT DATABASE:<br/>Error al seleccionar la Base de Datos:
'.mysql_error()."<br/>DETALLE ERROR:<br/>".mysql_error());
exit();
return false;
}
else
{
return $this->connection;
}
}
}
/**
* Metodo que ejecuta sentencias (INSERT, UPDATE & DELETE) y devuelve un resultado
* @param $prepareStatement or $query
* @return the $resultSet
*/
public function ExecuteUpdate($prepareStatement)
{
if(!($prepareStatement))
{
echo 'ERROR QUERY:<br/>Error recibir prepareStatement
'.mysql_error()."<br/>DETALLE ERROR:<br/>".mysql_error();
exit();
return false;
}
else
{
$resultSet = mysql_query($prepareStatement, $this->connection);
if(!($resultSet))
{
echo 'ERROR EXECUTE QUERY:\n Error al ejecutar
prepareStatement'.mysql_error()."\n DETALLE ERROR:\n".mysql_error();
exit();
return false;
}
else
{
return $resultSet;
}
}
}
/**
* Metodo que ejecuta SELECT y devuelve un resultado
* @param $statement or $query
* @return the $resultSet
*/
public function ExecuteQuery($statement)
{
if(!($statement))
{
echo 'ERROR QUERY:\n Error recibir statement '.mysql_error()."\n DETALLE
ERROR:\n".mysql_error();
exit();
return false;
}
else
{
$resultSet = mysql_query($statement, $this->connection);
if(!($resultSet))
{
echo 'ERROR EXECUTE QUERY:\n Error al ejecutar statement '.mysql_error()."\n
DETALLE ERROR:\n".mysql_error();
exit();
return false;
}
else
{
return $resultSet;
}
}
}
/**
* Metodo que guarda las sentencias para mostrarlas
* @param $statement or $query
* @return the $resultSet
*/
public function ResultSet($statement)
{
if(!($statement))
{
echo 'ERROR RESULTSET QUERY:\n Error al sentencia esta vacia o errada
'.mysql_error()."\n DETALLE ERROR:\n".mysql_error();
exit();
return false;
}
else
{
$resultSet = mysql_fetch_array($statement);
if(!($resultSet))
{
echo 'ERROR RESULTSET:\n Error al resultSet esta vacio '.mysql_error()."\n
DETALLE ERROR:\n".mysql_error();
exit();
return false;
}
else
{
return $resultSet;
}
}
}
/**
* Metodo para cerrar la conexion con el servicio de MySql PHP
* @return the $connection closed
*/
public function CloseMySQLConnection()
{
mysql_close($this->connection);
}