ClaveAudio_Web/admin/shoop/_incl/mysql.class.php
2011-05-06 11:33:27 +00:00

92 lines
2.1 KiB
PHP

<?php
// ####################################################
// datosClass.php
// una clase generica para manejar mySQL
// © ff 2005
class datosClass{
var $miConexion;
var $miQueryRsrc;
var $lastQuery;
var $numOfRows;
var $currentRow;
function datosClass($user, $password, $database, $host = 'localhost'){
$this->miConexion = false;
$this->lastQuery = '';
$this->miQueryRsrc = false;
$this->miConexion = @mysql_pconnect($host, $user, $password);
if ($this->miConexion) {
if (!@mysql_select_db($database, $this->miConexion)) {
$this->miConexion = false;
}
}
return $this->miConexion;
}
function query($query) {
$valor = false;
if($this->miConexion) {
$result = mysql_query($query, $this->miConexion);
if ($result) {
$this->lastQuery = strtoupper(substr($query, 0, strpos($query, ' ')));
if($this->lastQuery == 'SELECT') {
$this->miQueryRsrc = $result;
$this->numOfRows = $this->getNumOfRows();
$this->currentRow = 0;
}
$valor = true;
}
}
return $valor;
}
function getNumOfRows() {
if($this->lastQuery == 'SELECT') {
return mysql_num_rows($this->miQueryRsrc);
} else {
return mysql_affected_rows($this->miConexion);
}
}
function getLastID() {
return mysql_insert_id($this->miConexion);
}
function getNext() {
$this->currentRow ++;
$row = mysql_fetch_array($this->miQueryRsrc);
return $row;
}
function getFirst() {
mysql_data_seek($this->miQueryRsrc, 0);
return $this->getNext();
}
function getPrev() {
if($this->currentRow > 0) {
mysql_data_seek($this->miQueryRsrc, $this->currentRow);
return $this->getNext();
} else {
return false;
}
}
function getLast() {
mysql_data_seek($this->miQueryRsrc, $this->numOfRows - 1);
return $this->getNext();
}
function hasError() {
return mysql_errorno($this->miConexion);
}
function getError() {
return array( 'text' => mysql_error($this->miConexion),
'num' => mysql_errno($this->miConexion));
}
}
?>