473,411 Members | 2,164 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

I resolved that problem...

I created two classes Conexion.php and Consulta.php, I show you the
code:

/*
Clase Conexion:
Clase encargada de conectarse directamente con la base de datos de
MySQL.
*/
class Conexion {
var $vinculo;
var $resultado;
var $sentenciaSQL;

/*
Función iniciarConexion():
Función para iniciar la conexión con la base de datos.
Parámetros:
Ninguno.
Retorno:
TRUE si la conexión se logra correctamente.
FALSE si la conexion no se logra correctamente.
*/
function iniciarConexion()
{
$this->vinculo = mysql_connect(SISTEMA_HOST.":".SISTEMA_PORT,
SISTEMA_USERNAME, SISTEMA_PASSWORD);
if ($this->vinculo == false) {
return FALSE;
exit();
}
if (!mysql_select_db(SISTEMA_DATABASE, $this->vinculo)) {
return FALSE;
exit();
}
return TRUE;
}

/*
Función cerrarConexión():
Función para cerrar la conexión con la base de datos.
Parámetros:
Ninguno.
Retorno:
TRUE si la desconexion se logra correctamente.
FALSE si la desconexión no se logra correctmente.
*/
function cerrarConexion()
{
if (!mysql_close($this->vinculo)) {
return FALSE;
exit();
}
return TRUE;
}

/*
Función consultaInternaSQL():
Función para hacer una consulta a la base de datos.
Parámetros:
Cadena de caracteres con la consulta en SQL.
Retorno:
TRUE si la consulta se logra correctamente.
FALSE si la consulta se logra correctamente.
*/
function consultaInternaSQL($sql)
{
$this->sentenciaSQL = $sql;
$this->resultado = mysql_query($sql, $this->vinculo);
if (!$this->resultado) {
return FALSE;
exit();
}
return TRUE;
}

/*
Función obtenerDatos():
Función para obtener los datos de la consulta SQL realizada.
Parámetros:
Tipo de asociación de los datos de la consulta: Asociativo, Numérico
o Ambos.
Retorno:
FALSE si la obtencion no resulta satisfactoria.
Array con la información de la consulta.
*/
function obtenerDatos($arrayType = SISTEMA_ASSOC)
{
if (!$this->resultado) {
return FALSE;
exit();
}

switch ($arrayType) {
case SISTEMA_ASSOC:
$mysqlArrayType = MYSQL_ASSOC;
break;
case SISTEMA_NUM:
$mysqlArrayType = MYSQL_NUM;
break;
case SISTEMA_BOTH:
$mysqlArrayType = MYSQL_BOTH;
break;
default:
$mysqlArrayType = MYSQL_ASSOC;
}

$temporal = array();
while ($dato = mysql_fetch_array($this->resultado, $mysqlArrayType))
array_push($temporal, $dato);

$datos = array();
while (sizeof($temporal)) array_push($datos, array_pop($temporal));

return $datos;

}

/*
Función numeroTuplasAfectadas():
Función para saber el número de tuplas afectadas por una sentencia
INSERT, UPDATE ó DELETE.
Parámetros:
Ninguno.
Retorno:
Número de tuplas afectadas.
*/
function numeroTuplasAfectadas()
{
return mysql_affected_rows($this->vinculo);
}

/*
Función numeroTuplasResultado():
Función para saber el número de tuplas de un resultado SQL.
Parámetros:
Ninguno.
Retorno:
Número de tuplas del resultado.
*/
function numeroTuplasResultado()
{
if (stristr($this->sentenciaSQL, "select") OR stristr($this-
>sentenciaSQL, "SELECT"))
return mysql_num_rows($this->resultado);
else return 0;
}
}

And the second class...

require_once("Conexion.php");

class Consulta {
var $conexion;
var $cadenaSQL = "";
var $consulta;

function conectar() {
$this->conexion = new Conexion();
$this->conexion->iniciarConexion();
}

function desconectar() {
$this->conexion->cerrarConexion();
unset($this->conexion);
}

function consultaExternaSQL($sql, $arrayType = SISTEMA_ASSOC) {
$this->consulta = NULL;
$this->cadenaSQL = $sql;
$this->conectar();
$this->conexion->consultaInternaSQL($sql);
if ($this->conexion->numeroTuplasResultado() 0) $this->consulta =
$this->obtenerDatos($arrayType);
$this->desconectar();
return $this->obtenerResultado();
}

function obtenerDatos($arrayType) {
return $this->conexion->obtenerDatos($arrayType);
}

function obtenerResultado() {
return $this->consulta;
}

function obtenerSQL() {
return $this->cadenaSQL;
}

function obtenerSiguienteIdentificadorTabla($nombreTabla) {
$consulta = $this->consultaExternaSQL("SELECT max(id) AS maximo FROM
".$nombreTabla."");
$consulta = array_pop($consulta);
if (!empty($consulta['maximo'])) return $consulta['maximo'] + 1;
else return 1;
}

}
Nov 27 '07 #1
1 2123
On Nov 27, 9:28 pm, laastos <laas...@gmail.comwrote:
I created two classes Conexion.php and Consulta.php, I show you the
code:

/*
Clase Conexion:
Clase encargada de conectarse directamente con la base de datos de
MySQL.
*/
class Conexion {
var $vinculo;
var $resultado;
var $sentenciaSQL;

/*
Función iniciarConexion():
Función para iniciar la conexión con la base de datos.
Parámetros:
Ninguno.
Retorno:
TRUE si la conexión se logra correctamente.
FALSE si la conexion no se logra correctamente.
*/
function iniciarConexion()
{
$this->vinculo = mysql_connect(SISTEMA_HOST.":".SISTEMA_PORT,
SISTEMA_USERNAME, SISTEMA_PASSWORD);
if ($this->vinculo == false) {
return FALSE;
exit();
}
if (!mysql_select_db(SISTEMA_DATABASE, $this->vinculo)) {
return FALSE;
exit();
}
return TRUE;
}

/*
Función cerrarConexión():
Función para cerrar la conexión con la base de datos.
Parámetros:
Ninguno.
Retorno:
TRUE si la desconexion se logra correctamente.
FALSE si la desconexión no se logra correctmente.
*/
function cerrarConexion()
{
if (!mysql_close($this->vinculo)) {
return FALSE;
exit();
}
return TRUE;
}

/*
Función consultaInternaSQL():
Función para hacer una consulta a la base de datos.
Parámetros:
Cadena de caracteres con la consulta en SQL.
Retorno:
TRUE si la consulta se logra correctamente.
FALSE si la consulta se logra correctamente.
*/
function consultaInternaSQL($sql)
{
$this->sentenciaSQL = $sql;
$this->resultado = mysql_query($sql, $this->vinculo);
if (!$this->resultado) {
return FALSE;
exit();
}
return TRUE;
}

/*
Función obtenerDatos():
Función para obtener los datos de la consulta SQL realizada.
Parámetros:
Tipo de asociación de los datos de la consulta: Asociativo, Numérico
o Ambos.
Retorno:
FALSE si la obtencion no resulta satisfactoria.
Array con la información de la consulta.
*/
function obtenerDatos($arrayType = SISTEMA_ASSOC)
{
if (!$this->resultado) {
return FALSE;
exit();
}

switch ($arrayType) {
case SISTEMA_ASSOC:
$mysqlArrayType = MYSQL_ASSOC;
break;
case SISTEMA_NUM:
$mysqlArrayType = MYSQL_NUM;
break;
case SISTEMA_BOTH:
$mysqlArrayType = MYSQL_BOTH;
break;
default:
$mysqlArrayType = MYSQL_ASSOC;
}

$temporal = array();
while ($dato = mysql_fetch_array($this->resultado, $mysqlArrayType))
array_push($temporal, $dato);

$datos = array();
while (sizeof($temporal)) array_push($datos, array_pop($temporal));

return $datos;

}

/*
Función numeroTuplasAfectadas():
Función para saber el número de tuplas afectadas por una sentencia
INSERT, UPDATE ó DELETE.
Parámetros:
Ninguno.
Retorno:
Número de tuplas afectadas.
*/
function numeroTuplasAfectadas()
{
return mysql_affected_rows($this->vinculo);
}

/*
Función numeroTuplasResultado():
Función para saber el número de tuplas de un resultado SQL.
Parámetros:
Ninguno.
Retorno:
Número de tuplas del resultado.
*/
function numeroTuplasResultado()
{
if (stristr($this->sentenciaSQL, "select") OR stristr($this->sentenciaSQL, "SELECT"))

return mysql_num_rows($this->resultado);
else return 0;
}

}

And the second class...

require_once("Conexion.php");

class Consulta {
var $conexion;
var $cadenaSQL = "";
var $consulta;

function conectar() {
$this->conexion = new Conexion();
$this->conexion->iniciarConexion();
}

function desconectar() {
$this->conexion->cerrarConexion();
unset($this->conexion);
}

function consultaExternaSQL($sql, $arrayType = SISTEMA_ASSOC) {
$this->consulta = NULL;
$this->cadenaSQL = $sql;
$this->conectar();
$this->conexion->consultaInternaSQL($sql);
if ($this->conexion->numeroTuplasResultado() 0) $this->consulta =
$this->obtenerDatos($arrayType);
$this->desconectar();
return $this->obtenerResultado();
}

function obtenerDatos($arrayType) {
return $this->conexion->obtenerDatos($arrayType);
}

function obtenerResultado() {
return $this->consulta;
}

function obtenerSQL() {
return $this->cadenaSQL;
}

function obtenerSiguienteIdentificadorTabla($nombreTabla) {
$consulta = $this->consultaExternaSQL("SELECT max(id) ASmaximo FROM
".$nombreTabla."");
$consulta = array_pop($consulta);
if (!empty($consulta['maximo'])) return $consulta['maximo'] + 1;
else return 1;
}

}
hm?

--
Kailash Nadh | http://kailashnadh.name
Nov 27 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Efy. | last post by:
Hello, The following problam description I did not need to write, I just copied from the groups from others which met the error and allways the thread was 1 artical the problem was never...
2
by: Orantas Gladkauskas | last post by:
Hello everybody, I'm using Visual Studio 2003. Everything was fine until yesterday. I cannot add a WebBrowser or any other COM component on windows form any more. Every time I open a form in...
48
by: Luca Pinasco | last post by:
Hello I think I resolved a lot of things about this component that before didn't function correctly... I don't know, if you are interested on this...anyway, I can send the project to people ask...
11
by: Jack | last post by:
I have a asp form where among others there are few text boxes and one check box. The checkbox is to indicate whether the entry is final. The checkbox is attahced to a field in table of type...
2
by: niklesh | last post by:
Dear all, when i am trying to giving web reference to webservices i am getting above said error.. i tried to find out what is the main problem then i got from microsoft support that i have to...
8
by: Mark A. Sam | last post by:
Hello I am working locally with Visual Web Developer 2005 Express. Before I even installed it, the information from Microsoft was that you could FTP it to a remote site and it should work. The...
6
by: =?Utf-8?B?Wm9vZG9y?= | last post by:
I have a ClickOnce application that uses web services. This works from every machine we can test it on; however, a customer has a laptop that fails with an exception (relevant portion of stack...
3
by: amanjsingh | last post by:
Hi, I am trying to implement Java Web Service using Apache Axis2 and Eclipse as a tool. I have created the basic code and deployed the service using various eclipse plugin but when I try to invoke...
3
by: MLH | last post by:
I put the following Count() From tblPHPDeveloperDoItems Where = True in a report footer. It's OK at compile time. But when the report runs - it gives me an error. Is there something I can do...
5
by: David Portabella | last post by:
Hello, I have the following template class: ++++++++++++++++++++++ template <class Valueclass Test { public: void f() { if (typeid(Value) == typeid(string)) cout << "Value is a string" <<...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.