• <small id='TQ4FZ'></small><noframes id='TQ4FZ'>

  • <legend id='TQ4FZ'><style id='TQ4FZ'><dir id='TQ4FZ'><q id='TQ4FZ'></q></dir></style></legend>

    1. <i id='TQ4FZ'><tr id='TQ4FZ'><dt id='TQ4FZ'><q id='TQ4FZ'><span id='TQ4FZ'><b id='TQ4FZ'><form id='TQ4FZ'><ins id='TQ4FZ'></ins><ul id='TQ4FZ'></ul><sub id='TQ4FZ'></sub></form><legend id='TQ4FZ'></legend><bdo id='TQ4FZ'><pre id='TQ4FZ'><center id='TQ4FZ'></center></pre></bdo></b><th id='TQ4FZ'></th></span></q></dt></tr></i><div id='TQ4FZ'><tfoot id='TQ4FZ'></tfoot><dl id='TQ4FZ'><fieldset id='TQ4FZ'></fieldset></dl></div>
      <tfoot id='TQ4FZ'></tfoot>

        <bdo id='TQ4FZ'></bdo><ul id='TQ4FZ'></ul>

        PDO 连接从命令行工作,而不是通过 Apache?

        时间:2023-10-05
        <legend id='OF778'><style id='OF778'><dir id='OF778'><q id='OF778'></q></dir></style></legend><tfoot id='OF778'></tfoot>

            • <bdo id='OF778'></bdo><ul id='OF778'></ul>

              <small id='OF778'></small><noframes id='OF778'>

                  <tbody id='OF778'></tbody>
                • <i id='OF778'><tr id='OF778'><dt id='OF778'><q id='OF778'><span id='OF778'><b id='OF778'><form id='OF778'><ins id='OF778'></ins><ul id='OF778'></ul><sub id='OF778'></sub></form><legend id='OF778'></legend><bdo id='OF778'><pre id='OF778'><center id='OF778'></center></pre></bdo></b><th id='OF778'></th></span></q></dt></tr></i><div id='OF778'><tfoot id='OF778'></tfoot><dl id='OF778'><fieldset id='OF778'></fieldset></dl></div>
                  本文介绍了PDO 连接从命令行工作,而不是通过 Apache?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有一个非常简单的测试脚本:

                  I have a very simple test script:

                  <?php
                  
                  $DSN = "mysql:host=db.example.edu;port=3306;dbname=search_data";
                  
                  try {
                  
                      $DB = new PDO($DSN, "username", "super-secret-password!");
                  
                  } catch (PDOException $e) {
                  
                      header('Content-Type: text/plain');
                      print "Could not connect to database, rawr. :-(";
                      exit;
                  
                  }
                  
                  
                  $SQL = "SELECT phrase FROM search ORDER BY RAND() LIMIT 10";
                  
                  foreach($DB->query($SQL) as $row){
                  
                      print $row['phrase']."
                  ";
                  
                  }
                  
                  ?>
                  

                  当我从命令行执行此脚本时,它运行良好:

                  When I execute this script from the command line, it works perfectly:

                  $ php test.php
                  corporal punishment
                  Stretches
                  voluntary agencies and the resettlement of refugees
                  music and learning
                  Nike Tiger Woods Scandal
                  Hermeneia
                  PSYCHINFO
                  anthony bourdain
                  Black-White Couples and their Social Worlds
                  colonization, hodge
                  

                  但是当我通过网络浏览器访问完全相同的脚本时,它说:

                  But when I access the exact same script through my web browser, it says:

                  Could not connect to database, rawr. :-(
                  

                  我已经尝试了 var_dump 解决错误,消息是:SQLSTATE[HY000] [2003] 无法连接到 MySQL 服务器上的 'db.example.edu' (13)".

                  I've tried var_dump on the error, and the message is: "SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'db.example.edu' (13)".

                  这令人费解.这是完全相同的服务器上的完全相同的脚本——为什么当我从命令行执行它时它可以工作,但当 Apache 执行它时却失败?

                  This is puzzling. It's the exact same script on the exact same server -- why does it work when I execute it from the command line, but fail when Apache executes it?

                  推荐答案

                  如果这是运行 SELinux(或任何使用 SELinux 的任何非 Red Hat 衍生产品)的 Red Hat 衍生发行版(RHEL、CentOS、Fedora、ScientificLinux),则默认撰写本文时的策略设置是禁止 Apache 与其他服务器或数据库建立外部连接.作为 root,您必须启用以下两个 SELinux 布尔值.使用 -P 选项在重新启动后保持更改.

                  If this is a Red Hat-derived distribution (RHEL, CentOS, Fedora, ScientificLinux) running SELinux (or any non Red Hat derivative using SELinux), the default policy setting at time of this writing is to prohibit Apache from making external connections to other servers or databases. As root, you must enable the following two SELinux booleans. Use the -P option to persist the change across a reboot.

                  setsebool -P httpd_can_network_connect=1
                  setsebool -P httpd_can_network_connect_db=1
                  

                  请注意,httpd_can_network_connect 可能不是必需的.首先尝试仅打开 httpd_can_network_connect_db.

                  Note that httpd_can_network_connect may not be necessary. Try it first turning on only httpd_can_network_connect_db.

                  这篇关于PDO 连接从命令行工作,而不是通过 Apache?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何使用 CentOS 启用 PDO? 下一篇:MSSQL PDO 找不到驱动程序

                  相关文章

                  最新文章

                    <bdo id='Cy7pV'></bdo><ul id='Cy7pV'></ul>

                    <small id='Cy7pV'></small><noframes id='Cy7pV'>

                    <tfoot id='Cy7pV'></tfoot><legend id='Cy7pV'><style id='Cy7pV'><dir id='Cy7pV'><q id='Cy7pV'></q></dir></style></legend>
                    <i id='Cy7pV'><tr id='Cy7pV'><dt id='Cy7pV'><q id='Cy7pV'><span id='Cy7pV'><b id='Cy7pV'><form id='Cy7pV'><ins id='Cy7pV'></ins><ul id='Cy7pV'></ul><sub id='Cy7pV'></sub></form><legend id='Cy7pV'></legend><bdo id='Cy7pV'><pre id='Cy7pV'><center id='Cy7pV'></center></pre></bdo></b><th id='Cy7pV'></th></span></q></dt></tr></i><div id='Cy7pV'><tfoot id='Cy7pV'></tfoot><dl id='Cy7pV'><fieldset id='Cy7pV'></fieldset></dl></div>