3

In this code must be an error due to empty arguments in the mysqli_connect function. But browser display different error. As I know mysqli_connect function installed by default. Where is the problem or my mistake? How I can fix it?

Dockerfile

FROM php:fpm

# Update system core
RUN apt update -y && apt upgrade -y

# Start PHP-FPM
CMD ["php-fpm"]

index.php

<?php mysqli_connect('', '', '', '', '', ''); ?>

Error in browser:

Fatal error: Uncaught Error: Call to undefined function mysqli_connect() in /var/www/index.php:3 Stack trace: #0 {main} thrown in /var/www/index.php on line 3
LeXxyIT
  • 204
  • 2
  • 15
  • 4
    Sounds like mysqli has not been installed – aynber Feb 26 '20 at 14:08
  • @LexXy You need to get in the habit of [accepting answers](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) which help you to solve your issues. You'll earn points and others will be encouraged to help you. – Jay Blanchard Feb 26 '20 at 14:18

2 Answers2

6

In your Dockerfile for PHP-FPM (I recommend the Alpine version) you have to install MySQLi extension separately

FROM php:7-fpm-alpine

# Update system core
RUN apt update -y && apt upgrade -y
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli

# Start PHP-FPM
CMD ["php-fpm"]
Jay Blanchard
  • 34,243
  • 16
  • 77
  • 119
1

In Dockerfile you need add mysqli extension:

FROM php:7.3-fpm

# Update system core

RUN apt update && apt install -y \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libpng-dev libxml2-dev libcurl4-gnutls-dev


RUN docker-php-ext-install -j$(nproc) mysqli \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install -j$(nproc) gd

# Start PHP-FPM
CMD ["php-fpm"]
Dmitry Leiko
  • 3,970
  • 3
  • 25
  • 42
  • 2
    Please reduce your answer to the relevant parts - there is no need to install a ton of other extensions if only a MySQL connector is needed – Nico Haase Feb 26 '20 at 14:28
  • I have this error: ERROR: Service 'php-fpm' failed to build: The command '/bin/sh -c apt update && apt install -y libfreetype6-dev libjpeg62-turbo-dev libpng-dev libxml2-dev libcurl4-gnutls-dev' returned a non-zero code: 127 – LeXxyIT Feb 26 '20 at 14:37