Skip to content

Commit

Permalink
refs #6296 maybe we can detect number of rows matched by the UPDATE q…
Browse files Browse the repository at this point in the history
…uery, by using Mysql client flags in both Mysqli and PDO
  • Loading branch information
mattab committed Sep 28, 2014
1 parent 76865be commit 0b91a86
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 8 additions & 1 deletion core/Tracker/Db/Mysqli.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,14 @@ public function connect()
$timer = $this->initProfiler();
}

$this->connection = mysqli_connect($this->host, $this->username, $this->password, $this->dbname, $this->port, $this->socket);
$link = mysqli_init();

// Make sure MySQL returns all matched rows on update queries including
// rows that actually didn't have to be updated because the values didn't
// change. This matches common behaviour among other database systems.
// See #6296 why this is important in tracker
$flags = MYSQLI_CLIENT_FOUND_ROWS;
$this->connection = mysqli_real_connect($link, $this->host, $this->username, $this->password, $this->dbname, $this->port, $this->socket, $flags);
if (!$this->connection || mysqli_connect_errno()) {
throw new DbException("Connect failed: " . mysqli_connect_error());
}
Expand Down
7 changes: 7 additions & 0 deletions core/Tracker/Db/Pdo/Mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ public function connect()

$this->connection = @new PDO($this->dsn, $this->username, $this->password, $config = array());
$this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

// Make sure MySQL returns all matched rows on update queries including
// rows that actually didn't have to be updated because the values didn't
// change. This matches common behaviour among other database systems.
// See #6296 why this is important in tracker
$this->connection->setAttribute(PDO::MYSQL_ATTR_FOUND_ROWS, true);

// we may want to setAttribute(PDO::ATTR_TIMEOUT ) to a few seconds (default is 60) in case the DB is locked
// the piwik.php would stay waiting for the database... bad!
// we delete the password from this object "just in case" it could be printed
Expand Down

0 comments on commit 0b91a86

Please sign in to comment.