Edit File by line
/home/barbar84/www/wp-conte.../plugins/worker/src/MWP/Incremen.../Database
File: PdoConnection.php
<?php
[0] Fix | Delete
/*
[1] Fix | Delete
* This file is part of the ManageWP Worker plugin.
[2] Fix | Delete
*
[3] Fix | Delete
* (c) ManageWP LLC <contact@managewp.com>
[4] Fix | Delete
*
[5] Fix | Delete
* For the full copyright and license information, please view the LICENSE
[6] Fix | Delete
* file that was distributed with this source code.
[7] Fix | Delete
*/
[8] Fix | Delete
[9] Fix | Delete
class MWP_IncrementalBackup_Database_PdoConnection implements MWP_IncrementalBackup_Database_ConnectionInterface
[10] Fix | Delete
{
[11] Fix | Delete
[12] Fix | Delete
/**
[13] Fix | Delete
* @var MWP_IncrementalBackup_Database_Configuration
[14] Fix | Delete
*/
[15] Fix | Delete
private $configuration;
[16] Fix | Delete
[17] Fix | Delete
/**
[18] Fix | Delete
* @var PDO
[19] Fix | Delete
*/
[20] Fix | Delete
private $connection;
[21] Fix | Delete
[22] Fix | Delete
public function __construct(MWP_IncrementalBackup_Database_Configuration $configuration)
[23] Fix | Delete
{
[24] Fix | Delete
$this->configuration = $configuration;
[25] Fix | Delete
[26] Fix | Delete
if (!extension_loaded('pdo_mysql')) {
[27] Fix | Delete
throw new MWP_IncrementalBackup_Database_Exception_ConnectionException("PDO extension is disabled.");
[28] Fix | Delete
}
[29] Fix | Delete
[30] Fix | Delete
$options = array(
[31] Fix | Delete
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
[32] Fix | Delete
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
[33] Fix | Delete
);
[34] Fix | Delete
[35] Fix | Delete
// Mute the constructor since this error doesn't get thrown as an exception, but as a PHP warning:
[36] Fix | Delete
// Warning: PDO::__construct(): The server requested authentication method unknown to the client [mysql_old_password]
[37] Fix | Delete
$this->connection = @new PDO(self::getDsn($this->configuration), $this->configuration->getUsername(), $this->configuration->getPassword(), $options);
[38] Fix | Delete
[39] Fix | Delete
$this->connection->exec('SET NAMES '.$configuration->getCharset());
[40] Fix | Delete
}
[41] Fix | Delete
[42] Fix | Delete
/**
[43] Fix | Delete
* {@inheritdoc}
[44] Fix | Delete
*/
[45] Fix | Delete
public function query($query, $useResult = false)
[46] Fix | Delete
{
[47] Fix | Delete
/** @handled constant */
[48] Fix | Delete
$previousAttr = $this->connection->getAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY);
[49] Fix | Delete
[50] Fix | Delete
if ($useResult) {
[51] Fix | Delete
// Temporarily switch to unbuffered queries
[52] Fix | Delete
/** @handled constant */
[53] Fix | Delete
$this->connection->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
[54] Fix | Delete
}
[55] Fix | Delete
[56] Fix | Delete
$statement = new MWP_IncrementalBackup_Database_PdoStatement($this->connection->query($query));
[57] Fix | Delete
[58] Fix | Delete
if ($useResult) {
[59] Fix | Delete
// Restore configuration
[60] Fix | Delete
/** @handled constant */
[61] Fix | Delete
$this->connection->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, $previousAttr);
[62] Fix | Delete
}
[63] Fix | Delete
[64] Fix | Delete
return $statement;
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
/**
[68] Fix | Delete
* {@inheritdoc}
[69] Fix | Delete
*/
[70] Fix | Delete
public function quote($value)
[71] Fix | Delete
{
[72] Fix | Delete
return $this->connection->quote($value);
[73] Fix | Delete
}
[74] Fix | Delete
[75] Fix | Delete
/**
[76] Fix | Delete
* @param MWP_IncrementalBackup_Database_Configuration $configuration
[77] Fix | Delete
*
[78] Fix | Delete
* @return string
[79] Fix | Delete
*/
[80] Fix | Delete
private static function getDsn(MWP_IncrementalBackup_Database_Configuration $configuration)
[81] Fix | Delete
{
[82] Fix | Delete
$pdoParameters = array(
[83] Fix | Delete
'dbname' => $configuration->getDatabase(),
[84] Fix | Delete
'charset' => $configuration->getCharset(),
[85] Fix | Delete
);
[86] Fix | Delete
[87] Fix | Delete
if ($configuration->isSocket()) {
[88] Fix | Delete
$pdoParameters['unix_socket'] = $configuration->getSocketPath();
[89] Fix | Delete
} else {
[90] Fix | Delete
$pdoParameters['host'] = $configuration->getHost();
[91] Fix | Delete
[92] Fix | Delete
if (($port = $configuration->getPort()) !== null) {
[93] Fix | Delete
$pdoParameters['port'] = $configuration->getPort();
[94] Fix | Delete
}
[95] Fix | Delete
}
[96] Fix | Delete
[97] Fix | Delete
$parameters = array();
[98] Fix | Delete
foreach ($pdoParameters as $name => $value) {
[99] Fix | Delete
$parameters[] = $name.'='.$value;
[100] Fix | Delete
}
[101] Fix | Delete
[102] Fix | Delete
$dsn = sprintf("mysql:%s", implode(';', $parameters));
[103] Fix | Delete
[104] Fix | Delete
return $dsn;
[105] Fix | Delete
}
[106] Fix | Delete
}
[107] Fix | Delete
[108] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function