【问题标题】:Docker Compose, Add MySQL support to PHP-FPM 7. Call to undefined function mysql_connect()Docker Compose,将 MySQL 支持添加到 PHP-FPM 7。调用未定义函数 mysql_connect()
【发布时间】:2017-04-25 20:46:11
【问题描述】:

我正在使用 Docker Compose 构建我的第一台 Docker 机器。我希望将 Docker 设置为具有 PHP-FPM 7、Nginx 和 MySQL(使用 MariaDB)。

这是我的 docker-compose.yml

version: '2'
services:
nginx:
image: nginx:latest
ports:
  - "80:80"
volumes:
  - ./nginx/site.conf:/etc/nginx/conf.d/default.conf
  - ./logs/nginx-error.log:/var/log/nginx/error.log
  - ./logs/nginx-access.log:/var/log/nginx/access.log
  - ./public:/usr/share/nginx/html
links:
  - phpfpm

phpfpm:
image: php:7-fpm
volumes:
  - ./public:/usr/share/nginx/html
  - ./logs/log.conf:/usr/local/etc/php-fpm.d/zz-log.conf

mariadb:
image: mariadb
environment:
  MYSQL_ROOT_PASSWORD: admin
  MYSQL_DATABASE: admin
  MYSQL_USER: admin
  MYSQL_PASSWORD: admin
volumes:
 - ./database:/var/lib/mysql

Docker 正确启动,但是当我尝试使用 mysql_connect 连接到 index.php 中的数据库时,出现错误:

致命错误:未捕获错误:调用 /usr/share/nginx/html/index.php:7 中未定义的函数 mysql_connect() 堆栈跟踪:在 /usr/share/nginx/html/ 中抛出 #0 {main}第 7 行的 index.php

这是我的 index.php

<?php
 $username = "admin";
 $password = "admin";
 $hostname = "localhost";

 //connection to the database
 $dbhandle = mysql_connect($hostname, $username, $password)
   or die("Unable to connect to MySQL");
 echo "Connected to MySQL<br>";
 ?>

如何设置 PHP-FPM 以使用 MySQL?

非常感谢

【问题讨论】:

  • 在 php7 mysql 扩展被删除。结束了。
  • 你应该使用MySQLi
  • How can I set up PHP-FPM to use MySQL? 使用适当的扩展名,如 MySQLi 或 PDO。见this

标签: php mysql nginx docker docker-compose


【解决方案1】:

每次在新代码中使用the mysql_ 数据库扩展时, a Kitten is strangled somewhere in the world,它已被弃用并且已经存在多年,并且在 PHP7 中永远消失了

您必须安装 PHP5.6 版本或更好地重构您的代码以使用 MYSQLI 或 PDO

【讨论】:

  • 如果可以的话,为了拯救小猫,我会投更多的票。
猜你喜欢
  • 1970-01-01
  • 2016-03-09
  • 2016-08-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-15
相关资源
最近更新 更多