summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorlook-was-here <look.was.here@outlook.com>2024-08-31 21:49:52 -0500
committerDamien Regad <dregad@mantisbt.org>2025-01-25 02:03:00 +0100
commit8d97170e8016b969505a29b8cd39f001294653a2 (patch)
tree89b3e5081548d48bce72ba90c9b75719fa08f4e8 /drivers
parentbe251d3ff570110b13f6b9577a372c5898980e19 (diff)
downloadadodb-8d97170e8016b969505a29b8cd39f001294653a2.tar.gz
adodb-8d97170e8016b969505a29b8cd39f001294653a2.tar.bz2
adodb-8d97170e8016b969505a29b8cd39f001294653a2.zip
mysqli: Improve setConnectionParameter
- Simplify control statements with single if expressions. - Updated phpdoc with additional details on how to set connection property values. - Removed to-do that seemed wrong since the user should use setConnectionParameter for those or set the property directly. - Allow setting of ssl cert property values, clientFlags, port, and socket using the standard setConnectionParameter functionality. Feedback updates: - Return false for special cases with type checks on sslsert, socket, clientflags, or port fail - Added invalid connection param to output. - Simplified isset checks. - Changed sslcert to ssl and simplified subkeys to ('key', 'cert', 'ca', 'capath', 'cipher'). - Removed code duplication. - is_numeric should be checking value not parameter Fixes #1044
Diffstat (limited to 'drivers')
-rw-r--r--drivers/adodb-mysqli.inc.php68
1 files changed, 60 insertions, 8 deletions
diff --git a/drivers/adodb-mysqli.inc.php b/drivers/adodb-mysqli.inc.php
index 7efd1878..a6678274 100644
--- a/drivers/adodb-mysqli.inc.php
+++ b/drivers/adodb-mysqli.inc.php
@@ -145,22 +145,74 @@ class ADODB_mysqli extends ADOConnection {
}
/**
- * Adds a parameter to the connection string.
+ * Adds a parameter to the connection string, can also set connection property values.
*
* Parameter must be one of the constants listed in mysqli_options().
* @see https://www.php.net/manual/en/mysqli.options.php
- *
- * @param int $parameter The parameter to set
- * @param string $value The value of the parameter
+ *
+ * OR
+ *
+ * Parameter must be a string matching one of the following special cases.
+ * 'ssl' - SSL values e.g. ('ssl' => ['ca' => '/path/to/ca.crt.pem'])
+ * 'clientflags' - Client flags of type 'MYSQLI_CLIENT_'
+ * @see https://www.php.net/manual/en/mysqli.real-connect.php
+ * @see https://www.php.net/manual/en/mysqli.constants.php
+ * 'socket' - The socket or named pipe that should be used
+ * 'port' - The port number to attempt to connect to the MySQL server
+ *
+ * @param string|int $parameter The parameter to set
+ * @param string|int|array $value The value of the parameter
*
* @return bool
*/
public function setConnectionParameter($parameter, $value) {
- if(!is_numeric($parameter)) {
- $this->outp_throw("Invalid connection parameter '$parameter'", __METHOD__);
- return false;
+
+ // Special case for setting SSL values.
+ if ("ssl" === $parameter && is_array($value)) {
+ if (isset($value["key"])) {
+ $this->ssl_key = $value["key"];
+ }
+ if (isset($value["cert"])) {
+ $this->ssl_cert = $value["cert"];
+ }
+ if (isset($value["ca"])) {
+ $this->ssl_ca = $value["ca"];
+ }
+ if (isset($value["capath"])) {
+ $this->ssl_capath = $value["capath"];
+ }
+ if (isset($value["cipher"])) {
+ $this->ssl_cipher = $value["cipher"];
+ }
+
+ return true;
}
- return parent::setConnectionParameter($parameter, $value);
+
+ // Special case for setting the client flag(s).
+ if ("clientflags" === $parameter && is_numeric($value)) {
+ $this->clientFlags = $value;
+ return true;
+ }
+
+ // Special case for setting the socket.
+ if ("socket" === $parameter && is_string($value)) {
+ $this->socket = $value;
+ return true;
+ }
+
+ // Special case for setting the port.
+ if ("port" === $parameter && is_numeric($value)) {
+ $this->port = (int)$value;
+ return true;
+ }
+
+ // Standard mysqli_options.
+ if (is_numeric($parameter)) {
+ return parent::setConnectionParameter($parameter, $value);
+ }
+
+ $this->outp_throw("Invalid connection parameter '$parameter'", __METHOD__);
+ return false;
}
/**