Skip to content

Commit

Permalink
add hostname in error messages (task for DAILY-36678)
Browse files Browse the repository at this point in the history
  • Loading branch information
hc committed Jan 26, 2015
1 parent b1021c6 commit 3312433
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions MyDBD.php
Expand Up @@ -319,7 +319,7 @@ protected function handleErrors($query = null)
{
if ($this->link->errno)
{
MyDBD_Error::throwError($this->link->errno, $this->link->error . ' /* ' . $this->dbName() . ' */', $this->link->sqlstate, $query);
MyDBD_Error::throwError($this->connectionInfo['hostname'], $this->link->errno, $this->link->error . ' /* ' . $this->dbName() . ' */', $this->link->sqlstate, $query);
}
}

Expand Down Expand Up @@ -442,7 +442,7 @@ public function prepare()
$this->lastQueryHandle = $stmt; // used by affectedRows()
$this->handleErrors();

$sth = new MyDBD_PreparedStatement($stmt, $this->options);
$sth = new MyDBD_PreparedStatement($stmt, $this->options, $this->connectionInfo);
try
{
$sth->prepare($query, $args);
Expand Down
4 changes: 3 additions & 1 deletion MyDBD/Error.php
Expand Up @@ -49,8 +49,10 @@ abstract class MyDBD_Error
2030 => 'SQLNotPreparedStatementException',
);

static public function throwError($errorno, $error, $sqlstate = null, $query = null, array $params = null)
static public function throwError($hostname, $errorno, $error, $sqlstate = null, $query = null, array $params = null)
{
$error .= ' on hostname: ' . $hostname;

if (isset($query))
{
$error .= ' for query: ' . $query;
Expand Down
10 changes: 6 additions & 4 deletions MyDBD/PreparedStatement.php
Expand Up @@ -13,6 +13,7 @@ class MyDBD_PreparedStatement
private
$stmt = null,
$options = null,
$connectionInfo = null,
$frozen = false,
$preparedQuery = null,
$resultSet = null,
Expand All @@ -23,10 +24,11 @@ class MyDBD_PreparedStatement
*
* @param mysqli_stmt $preparedStatement
*/
public function __construct(mysqli_stmt $preparedStatement, array $options)
public function __construct(mysqli_stmt $preparedStatement, array $options, array $connectionInfo)
{
$this->stmt = $preparedStatement;
$this->options = $options;
$this->stmt = $preparedStatement;
$this->options = $options;
$this->connectionInfo = $connectionInfo;
}

/**
Expand Down Expand Up @@ -323,7 +325,7 @@ protected function handleErrors($query = null, $params = null)
{
if ($this->stmt->errno)
{
MyDBD_Error::throwError($this->stmt->errno, $this->stmt->error, null, $query, $params);
MyDBD_Error::throwError($this->connectionInfo['hostname'], $this->stmt->errno, $this->stmt->error, null, $query, $params);
}
}
}

0 comments on commit 3312433

Please sign in to comment.