我已将我的项目从 AWS 迁移到 Google Cloud。我之前有一个工作应用程序,但现在迁移到 GCP 后,mysqli_connect 似乎不再工作。 到目前为止,我已经安装了以下内容:
- php-mysql-5.4.16-42.el7.x86_64
- php-pdo-5.4.16-42.el7.x86_64
- php-5.4.16-42.el7.x86_64
- php-common-5.4.16-42.el7.x86_64
- php-cli-5.4.16-42.el7.x86_64
- mariadb-libs-5.5.52-1.el7.x86_64
- mariadb-5.5.52-1.el7.x86_64
我可以使用终端访问 MySQL,但无法使用 PHP 连接到远程数据库(在 AWS RDS 上)。 RDS数据库对IP连接没有任何限制,对外开放。我试过完全删除 PHP、MySQL、MariaDB,但是没有成功。连接到数据库的脚本自迁移以来未更改。其他函数如 mysqli_fetch_assoc 和 mysqli_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/