Eliminado manejo de errores personalizados porque ya no es necesario en MySQL 5.5 (SIGNAL)

This commit is contained in:
Juan Ferrer Toribio 2015-08-17 20:04:47 +02:00
parent 1874018b12
commit b5f3e897d3
2 changed files with 14 additions and 59 deletions

View File

@ -1,5 +1,5 @@
Package: php-vn-lib Package: php-vn-lib
Version: 1.0-11 Version: 1.0-16
Architecture: all Architecture: all
Maintainer: Juan Ferrer Toribio <juan@verdnatura.es> Maintainer: Juan Ferrer Toribio <juan@verdnatura.es>
Depends: php5-mysql Depends: php5-mysql

View File

@ -20,11 +20,11 @@ class Conn
* *
* @return boolean %TRUE on success, %FALSE otherwise * @return boolean %TRUE on success, %FALSE otherwise
**/ **/
function open ($host, $user, $pass, $name) function open ($host, $user, $pass, $name, $port = NULL)
{ {
$conn = $this->conn = mysqli_init (); $conn = $this->conn = mysqli_init ();
$conn->options (MYSQLI_READ_DEFAULT_FILE, __DIR__.'/my.cnf'); $conn->options (MYSQLI_READ_DEFAULT_FILE, __DIR__.'/my.cnf');
@$conn->real_connect ($host, $user, $pass, $name); @$conn->real_connect ($host, $user, $pass, $name, $port);
if (mysqli_connect_errno ()) if (mysqli_connect_errno ())
{ {
@ -172,48 +172,24 @@ class Conn
return $this->conn->next_result (); return $this->conn->next_result ();
} }
/**
* Check if there has been an error in the last query or multiquery,
* throwing a @Db\Exception exception if any.
**/
function checkError () function checkError ()
{ {
if ($this->conn->errno) if ($this->conn->errno)
{ throw new Exception ($this->conn->errno, $this->conn->error);
$code = $this->conn->errno;
$message = $this->conn->error;
$sql = 'SELECT es_es message, 2000 + id AS id '.
'FROM sql_error WHERE code = @err';
if ($code == 1305 && ($row = $this->getRow ($sql)))
throw new Exception ($row['id'], $row['message']);
else
throw new Exception ($code, $message);
}
} }
/**
* Check if there have been warnings in the last query.
*
* @return boolean %TRUE if there have been warnings %FALSE otherwise
**/
function checkWarnings () function checkWarnings ()
{ {
if ($this->conn->warning_count > 0) return $this->conn->warning_count > 0;
if ($result = $this->conn->query ('SHOW WARNINGS'))
{
$warnings = [];
$sql = 'SELECT es_es message, 3000 + id AS id '.
'FROM sql_warning WHERE code = @warn';
while ($row = $result->fetch_assoc ())
{
if ($row['Code'] == 1265
&& ($warning = $this->getRow ($sql)))
{
$row['Code'] = $warning['id'];
$row['Message'] = $warning['message'];
}
$warnings[] = $row;
}
return $warnings;
}
return NULL;
} }
/** /**
@ -273,27 +249,6 @@ class Conn
else else
return 'NULL'; return 'NULL';
} }
/**
* Renders an SQL string using sprintf like style.
* DEPRECATED
*
* @return mixed The rendered SQL string
**/
static function renderf ($arg)
{
$count = count ($arg);
if ($count > 1)
{
for ($i = 1; $i < $count; $i++)
$arg[$i] = $this->renderValue ($arg[$i]);
return call_user_func_array ('sprintf', $arg);
}
else
return $arg[0];
}
} }
?> ?>