我从docker开始,我尝试使用mysql数据库运行一个简单的php应用程序。我在docker文件中安装了mysql驱动程序,并且在容器中看到了php信息,但是,当您尝试从php类连接到de数据库时,我遇到了典型的错误提示:“在/中调用未定义的函数mysql_open()代码/公共/index.php:5”。我尝试连接PDO(也已安装并在phpinfo中可见),并得到类似的错误(未找到PDO)。
这是我的代码
index.php
<?php
#phpinfo();
echo "Hola hi";
$link = mysql_open("mysql", "root", "frida", "");
if (!$link) {
echo "Error: Unable to connect to MySQL." . PHP_EOL;
echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
exit;
}
echo "Success: A proper connection to MySQL was made!" . PHP_EOL;
echo "Host information: " . mysqli_get_host_info($link) . PHP_EOL;
mysqli_close($link);
docker-compose.yml
version: '3'
services:
web:
build:
context: .
dockerfile: docker/nginx/Dockerfile
networks:
- red
ports:
- "8081:80"
volumes:
- .:/code/
links:
- php
php:
build:
context: .
dockerfile: docker/php/Dockerfile
networks:
- red
volumes:
- .:/code/
mysql:
#image: mysql:8.0
build:
context: .
dockerfile: docker/mysql/Dockerfile
# command: --default-authentication-plugin=mysql_native_password
networks:
- red
ports:
- "8083:3306"
restart: always
environment:
- MYSQL_ROOT_PASSWORD=frida
volumes:
- .:/code/
phpmyadmin:
depends_on:
- mysql
image: phpmyadmin/phpmyadmin
networks:
- red
ports:
- "8082:80"
restart: always
environment:
- MYSQL_USERNAME=root
- PMA_HOST=mysql
- MYSQL_ROOT_PASSWORD=frida
networks:
red:
用于PHP的Dofkerfile
FROM php:7.1-fpm-alpine
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
# Copy the php config file
COPY ./docker/php/php-fpm.conf /etc/php/7.1/fpm/pool.d/www.conf
# Copy the application code
COPY . /code
VOLUME ["/code"]
nginx的dockerfile
FROM nginx:1.11-alpine
# Copy the nginx config file
COPY ./docker/nginx/nginx.conf /etc/nginx/conf.d/default.conf
我进行了很多搜索,但是我能找到的所有信息都可以通过驱动程序设置来修复错误(并且我已经设置好了)