Differential D20780 Diff 49551 src/infrastructure/storage/connection/mysql/AphrontMySQLiDatabaseConnection.php
Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/storage/connection/mysql/AphrontMySQLiDatabaseConnection.php
Show First 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | protected function connect() { | ||||
if ($timeout) { | if ($timeout) { | ||||
$conn->options(MYSQLI_OPT_CONNECT_TIMEOUT, $timeout); | $conn->options(MYSQLI_OPT_CONNECT_TIMEOUT, $timeout); | ||||
} | } | ||||
if ($this->getPersistent()) { | if ($this->getPersistent()) { | ||||
$host = 'p:'.$host; | $host = 'p:'.$host; | ||||
} | } | ||||
@$conn->real_connect( | $trap = new PhutilErrorTrap(); | ||||
$ok = @$conn->real_connect( | |||||
$host, | $host, | ||||
$user, | $user, | ||||
$pass, | $pass, | ||||
$database, | $database, | ||||
$port); | $port); | ||||
$call_error = $trap->getErrorsAsString(); | |||||
$trap->destroy(); | |||||
$errno = $conn->connect_errno; | $errno = $conn->connect_errno; | ||||
if ($errno) { | if ($errno) { | ||||
$error = $conn->connect_error; | $error = $conn->connect_error; | ||||
$this->throwConnectionException($errno, $error, $user, $host); | $this->throwConnectionException($errno, $error, $user, $host); | ||||
} | } | ||||
// See T13403. If the parameters to "real_connect()" are wrong, it may | |||||
// fail without setting an error code. In this case, raise a generic | |||||
// exception. (One way to reproduce this is to pass a string to the | |||||
// "port" parameter.) | |||||
if (!$ok) { | |||||
if (strlen($call_error)) { | |||||
$message = pht( | |||||
'mysqli->real_connect() failed: %s', | |||||
$call_error); | |||||
} else { | |||||
$message = pht( | |||||
'mysqli->real_connect() failed, but did not set an error code '. | |||||
'or emit a message.'); | |||||
} | |||||
$this->throwConnectionException( | |||||
self::CALLERROR_CONNECT, | |||||
$message, | |||||
$user, | |||||
$host); | |||||
} | |||||
// See T13238. Attempt to prevent "LOAD DATA LOCAL INFILE", which allows a | // See T13238. Attempt to prevent "LOAD DATA LOCAL INFILE", which allows a | ||||
// malicious server to ask the client for any file. At time of writing, | // malicious server to ask the client for any file. At time of writing, | ||||
// this option MUST be set after "real_connect()" on all PHP versions. | // this option MUST be set after "real_connect()" on all PHP versions. | ||||
$conn->options(MYSQLI_OPT_LOCAL_INFILE, 0); | $conn->options(MYSQLI_OPT_LOCAL_INFILE, 0); | ||||
$this->connectionOpen = true; | $this->connectionOpen = true; | ||||
$ok = @$conn->set_charset('utf8mb4'); | $ok = @$conn->set_charset('utf8mb4'); | ||||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | if (!$result) { | ||||
if (!$error_code) { | if (!$error_code) { | ||||
if (strlen($err)) { | if (strlen($err)) { | ||||
$message = $err; | $message = $err; | ||||
} else { | } else { | ||||
$message = pht( | $message = pht( | ||||
'Call to "mysqli->query()" failed, but did not set an error '. | 'Call to "mysqli->query()" failed, but did not set an error '. | ||||
'code or emit an error message.'); | 'code or emit an error message.'); | ||||
} | } | ||||
$this->throwQueryCodeException(777777, $message); | $this->throwQueryCodeException(self::CALLERROR_QUERY, $message); | ||||
} | } | ||||
} | } | ||||
return $result; | return $result; | ||||
} | } | ||||
protected function rawQueries(array $raw_queries) { | protected function rawQueries(array $raw_queries) { | ||||
$conn = $this->requireConnection(); | $conn = $this->requireConnection(); | ||||
▲ Show 20 Lines • Show All 81 Lines • Show Last 20 Lines |