通过 ADODB 库的 MySQL SSL 连接

发布于 2024-07-27 22:22:46 字数 1252 浏览 4 评论 0原文

我有一个托管在远程服务器上的 MySQL 数据库,并且它只能接受 SSL 连接。 当我使用带有 SSL 选项的 Java JDBC 连接到该数据库时,它工作正常。 有一个特殊的 jdbc 字符串用于 JDBC 连接,如下所示 “jdbc:mysql://:/?verifyServerCertificate=false&useSSL=true&requireSSL=true”

我需要使用 ADODB 库通过 PHP 使用类似的连接。

我在网上发现了一些关于使用 ADODB mysqli 扩展的参考资料


(参考 http://mbrisby.blogspot.com/2008/06/adodb-php-mysql-ssl.html

创建 CA 证书后(我们会说它位于 /path/to/ca-cert.html)。 pem),请确保以下项目位于客户端主机上的 /etc/my.cnf 或连接用户的 ~/.my.cnf 的 [client] 节中:

ssl-ca=/path/to/ca-cert .pem

然后尝试以下 PHP 程序:

// 这些是 AdoDB 库的一部分 需要“/path/to/adodb-exceptions.inc.php”; 需要“/path/to/adodb.inc.php”;

/* * 我从跑步中得到了“2048” * printf( "%d\n", MYSQLI_CLIENT_SSL ) * 在 PHP 程序中(安装了 mysqli 扩展) */ $dsn = 'mysqli://ssluser:sslpass@dbhost/test?clientflags=2048';

$dbh = NewADOConnection($dsn);

$sql = "显示状态如'ssl_cipher'"; $res =& $dbh->执行($sql); print_r( $res->fields ); $res->关闭();

$dbh->关闭();



如果我从另一台机器连接到此 mysql 数据库,是否需要证书信息?

PHP 是否有类似于 JDBC 字符串的东西?

如果有人可以发布一个工作示例,那就太好了,

谢谢

I have a MySQL database hosted on a remote server and it is enabled to accept only SSL connection. When I connect to this database using Java JDBC with SSL options, it works fine. There is a special jdbc string that I use for JDBC connection as below
"jdbc:mysql://:/?verifyServerCertificate=false&useSSL=true&requireSSL=true"

I need to use similar connection through PHP using the ADODB library.

I found few references over the web about using the ADODB mysqli extension


(reference http://mbrisby.blogspot.com/2008/06/adodb-php-mysql-ssl.html)

After creating a CA certificate (we'll say it's at /path/to/ca-cert.pem), make sure that the following item is in the [client] stanza of /etc/my.cnf or the connecting user's ~/.my.cnf on the client host:

ssl-ca=/path/to/ca-cert.pem

Then try the following PHP program:

// these are part of the AdoDB library
require '/path/to/adodb-exceptions.inc.php';
require '/path/to/adodb.inc.php';

/*
* I got the '2048' from running
* printf( "%d\n", MYSQLI_CLIENT_SSL )
* in a PHP program (w/ the mysqli extention installed)
*/
$dsn = 'mysqli://ssluser:sslpass@dbhost/test?clientflags=2048';

$dbh = NewADOConnection($dsn);

$sql = "show status like 'ssl_cipher'";
$res =& $dbh->Execute($sql);
print_r( $res->fields );
$res->Close();

$dbh->Close();



Do I need the certificate information if I am connecting from a different machine to this mysql database?

Is there something similar to the JDBC string available for PHP?

It would be great if someone can post a working example

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甩你一脸翔 2024-08-03 22:22:46

我没有使用 SSL 连接 MySQL 的经验。 MySQL 驱动程序有 标志 (MYSQL_CLIENT_SSL)连接时可以使用。

要在使用 AdoDB 连接时进行设置,您可以尝试我的连接模板:

$options = '';
if ($driver == 'mysql' OR $driver == 'mysqli')
{
  if ($params['pconnect'] === TRUE)
  {
    $options .= '?persist';
  }
  $flags = MYSQL_CLIENT_COMPRESS;
  if ($params['ssl'] === TRUE)
  {
    $flags = $flags | MYSQL_CLIENT_SSL;
  }
  $options .= (empty($options)?'?':'&')."clientflags=$flags";
}

$dsn = "{$driver}://{$username}:{$password}@{$hostname}/{$database}{$options}";

$adodb =& ADONewConnection($dsn);

if ($adodb)
{
  //set fetch mode
  $adodb->SetFetchMode(ADODB_FETCH_BOTH);

  //character set
  if ($driver == 'mysql' OR $driver == 'mysqli')
  {
    if (isset($params['char_set']) AND $params['char_set']
        AND isset($params['dbcollat']) AND $params['dbcollat'])
    {
      $charset    = $adodb->qstr($params['char_set']);
      $collation  = $adodb->qstr($params['dbcollat']);
      $adodb->Execute("SET NAMES $charset COLLATE $collation");
    }
  }
  if ($debug)
  {
    @ob_start();
    $adodb->debug = TRUE;
  }
}

I have no experience connecting MySQL with SSL. MySQL driver have flags (MYSQL_CLIENT_SSL) that you can use when connecting.

To set it when connecting using AdoDB, you can try my connection template:

$options = '';
if ($driver == 'mysql' OR $driver == 'mysqli')
{
  if ($params['pconnect'] === TRUE)
  {
    $options .= '?persist';
  }
  $flags = MYSQL_CLIENT_COMPRESS;
  if ($params['ssl'] === TRUE)
  {
    $flags = $flags | MYSQL_CLIENT_SSL;
  }
  $options .= (empty($options)?'?':'&')."clientflags=$flags";
}

$dsn = "{$driver}://{$username}:{$password}@{$hostname}/{$database}{$options}";

$adodb =& ADONewConnection($dsn);

if ($adodb)
{
  //set fetch mode
  $adodb->SetFetchMode(ADODB_FETCH_BOTH);

  //character set
  if ($driver == 'mysql' OR $driver == 'mysqli')
  {
    if (isset($params['char_set']) AND $params['char_set']
        AND isset($params['dbcollat']) AND $params['dbcollat'])
    {
      $charset    = $adodb->qstr($params['char_set']);
      $collation  = $adodb->qstr($params['dbcollat']);
      $adodb->Execute("SET NAMES $charset COLLATE $collation");
    }
  }
  if ($debug)
  {
    @ob_start();
    $adodb->debug = TRUE;
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文