php - MySQL 在终端中工作,但在 PHP 中不工作

标签 php mysql amazon-web-services mysqli centos

我已将我的项目从 AWS 迁移到 Google Cloud。我之前有一个工作应用程序,但现在迁移到 GCP 后,mysqli_connect 似乎不再工作。 到目前为止,我已经安装了以下内容:

  1. php-mysql-5.4.16-42.el7.x86_64
  2. php-pdo-5.4.16-42.el7.x86_64
  3. php-5.4.16-42.el7.x86_64
  4. php-common-5.4.16-42.el7.x86_64
  5. php-cli-5.4.16-42.el7.x86_64
  6. mariadb-libs-5.5.52-1.el7.x86_64
  7. mariadb-5.5.52-1.el7.x86_64

我可以使用终端访问 MySQL,但无法使用 PHP 连接到远程数据库(在 AWS RDS 上)。 RDS数据库对IP连接没有任何限制,对外开放。我试过完全删除 PHP、MySQL、MariaDB,但是没有成功。连接到数据库的脚本自迁移以来未更改。其他函数如 mysqli_fetch_assocmysqli_query 没有抛出任何错误。以下是 mysqld_log 的内容:

170329 07:20:15 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
170329 07:31:09 mysqld_safe Logging to '/var/log/mysqld.log'.
170329 07:31:09 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
2017-03-29 07:31:09 0 [Warning] s deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-03-29 07:31:09 0 [Note] /usr/sbin/mysqld (mysqld 5.6.35) starting as process 32611 ...
2017-03-29 07:31:09 32611 [Warning] Buffered warning: Changed limits: max_open_files: 1024 (requested 5000)

2017-03-29 07:31:09 32611 [Warning] Buffered warning: Changed limits: table_open_cache: 431 (requested 2000)

2017-03-29 07:31:09 32611 [Note] Plugin 'FEDERATED' is disabled.
2017-03-29 07:31:09 32611 [Note] InnoDB: Using atomics to ref count buffer pool pages
2017-03-29 07:31:09 32611 [Note] InnoDB: The InnoDB memory heap is disabled
2017-03-29 07:31:09 32611 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2017-03-29 07:31:09 32611 [Note] InnoDB: Memory barrier is not used
2017-03-29 07:31:09 32611 [Note] InnoDB: Compressed tables use zlib 1.2.3
2017-03-29 07:31:09 32611 [Note] InnoDB: Using Linux native AIO
2017-03-29 07:31:09 32611 [Note] InnoDB: Using CPU crc32 instructions
2017-03-29 07:31:09 32611 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2017-03-29 07:31:09 32611 [Note] InnoDB: Completed initialization of buffer pool
2017-03-29 07:31:09 32611 [Note] InnoDB: Highest supported file format is Barracuda.
2017-03-29 07:31:09 32611 [Note] InnoDB: 128 rollback segment(s) are active.
2017-03-29 07:31:09 32611 [Note] InnoDB: Waiting for purge to start
2017-03-29 07:31:09 32611 [Note] InnoDB: 5.6.35 started; log sequence number 1626037
2017-03-29 07:31:09 32611 [Note] Server hostname (bind-address): '*'; port: 3306
2017-03-29 07:31:09 32611 [Note] IPv6 is available.
2017-03-29 07:31:09 32611 [Note]   - '::' resolves to '::';
2017-03-29 07:31:09 32611 [Note] Server socket created on IP: '::'.
2017-03-29 07:31:09 32611 [Note] Event Scheduler: Loaded 0 events
2017-03-29 07:31:09 32611 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.6.35'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MySQL Community Server (GPL)

最佳答案

你写道你使用mysqli_connect,但你已经安装了php-mysql-5.4.16-42.el7.x86_64(注意:没有'i')。您需要 mysqli 的包以便 PHP 连接。

关于php - MySQL 在终端中工作,但在 PHP 中不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43098374/

相关文章:

php - 在插入之前检查值,如果已经存在,请不要在php中使用mysql插入它

php - 如何通过传参获取月记录和年记录

json - AWS CLI-为参数分配多个值的语法是什么

php - MySQL,检查结果是否有值(value),如果没有则取另一个

mysql - 左连接三个表,将名称字段合并到一列中

python-3.x - libffi-d78936b1.so.6.0.4 : cannot open shared object file Error on AWS Lambda function

java - 将 sam 本地 api 连接到 secret 管理器时出现问题

php - 将变量传递给 mysql 语句

php - 使用 PHP Simple DOM Parser 进行递归

php - 通过代理的PHP套接字连接