12/28/2021

Pdo_mysql Docker

93

First of all, learn a method:

  1. Pdo_mysql Dockerfile
  2. Mysqli Pdo_mysql Docker

Use docker exec to enter the Docker container

May 29, 2020 I found this one very useful using docker-compose, and this one not using it, but I struggled trying to use PHP+PDO to simply open a connection with my MySQL database only reading these articles. The reason why I’d use PDO is that MySQLi extension has been deprecated, as W3C says. Sep 26, 2020 # Install the PDO MySQL extension so we can database RUN docker-php-ext-install pdomysql # Set up a web server CMD 'php', '-S', '0.0.0.0:8000' To note, I’ve placed both this Dockerfile as well as the PHP file in a folder called php. You'll need to be care­ful about the di­rec­tory struc­ture be­cause it will mat­ter for the next step.

Browse The Most Popular 8 Mysql Composer Pdo Open Source Projects. When using the PHP image inside of Docker, there are some extra steps needed when using certain PHP “Core” Extensions. If you see errors related to 'PDOMySQL' you may be missing the Docker extension. You can find more about extensions here: PHP: Membership - Manual Here is the page for PDOMySQL: PHP: MySQL (PDO) - Manual.

FROM php: fpm RUN docker-php-ext-install pdo pdomysql RUN pecl install xdebug && docker-php-ext-enable xdebug xdebug is installed through pecl, which is provided as part of the official PHP image.

After version 1.3.X, docker also provides a new command exec to enter the container. This is a relatively simple way. Let’s take a look at the use of this command:

Next, we use this command to enter a container that is already running.

I. Configuring nginx

Find the nginx image on Docker Hub

Here we take the official mirror.

After the download is completed, we can find the image of REPOSITORY as nginx in the local image list.

Create and run containers:

Be careful:

– V adds a file mapping relationship so that files changed on the host can be mapped directly to the container. The catalog here maps according to its actual situation.

After creating and running the container, nginx in docker will start up successfully. It is not necessary to start nginx again inside docker, otherwise it will prompt port 80 to be occupied, because nginx has been started.

At this time, you can access the domain name validation of nginx configuration.

The conf.d I mapped here mainly contains the configuration file of nginx. The configuration information of PHP is as follows:

Note the IP address of fastcgi_pass at the end, and the common problems with PHP configuration are described in detail.

II. PHP configuration

Find the PHP image on Docker Hub

Here we take the official image, labeled 5.6-fpm.

After the download is completed, we can find the image of REPOSITORY as PHP and labeled 5.6-fpm in the local image list.

Create and run PHP containers:

Note that you must create a file mapping here, or that there is a corresponding PHP code in the PHP container. The file mapping of nginx in the previous step is not found here. So if there is no file mapping, 127.0.0.1:9000 will not find the file in this container.

Common problem:

After starting the PHP container, if you access nginx: 502 Bad Gateway

Try the following methods:

View the IP address of the PHP image

For example: 192.168.4.202

Modify the conf configuration file of nginx to make fastcgi_pass 192.168.4.202:9000

vim /docker/nginx/conf.d/default.conf

fastcgi_pass 192.168.4.202:9000;

After restarting the nginx container, you can access it properly.

III. Mysql configuration

Find the MySQL image on Docker Hub

Here we take the official image, labeled 5.6.

Waiting for the download to complete, we can find the mirror with REPOSITORY as MySQL and label 5.6 in the local image list.

Create and run MySQL containers:

The main purpose of file mapping here is to map the SQL database data files of the host machine to the docker MySQL container for easy import. Note that the directory of the MySQL container here can not be an existing directory, otherwise it will be overwritten.

Be careful:

It’s easy to create here. My. CNF already exists, and you don’t need to add it yourself.

Docker

Expand

Connect MySQL within docker using external tool Navicat

The host of MySQL fills in the IP in docker by:

Fill in the SSH connection information:

Successful connection!

Be careful:

Docker’s container startup order problem will lead to inconsistent IP addresses of the container. If the IP of the container is used in connection with the database and fastcgi, pay attention to the startup order of the container.

Restart container: docker restart container name / container ID

Close the container: docker stop XXX

Open container: docker start XXX

Pdo_mysql

View the running container: dockers

View all containers (including those that are not running): docker PS-A

Create and run containers: docker run

—————————————

Common errors:

1. Thinkphp reported an error of Undefined class constant’MYSQL_ATTR_INIT_COMMAND’

Lack of pdo_mysql extension, failed to link database

Find php. ini, docker in / usr / local / etc / php, copy a copy of php. ini, add extension = pdo_mysql. so, restart phpfpm.

If not, visit the phpinfo page to see if there is pdo_mysql

If not, the name extension does not exist and needs to be compiled.

The compilation method is as follows:

It can be achieved in two ways

Mode 1 (not verified):

Pdo_mysql Dockerfile

pecl pdo_msql

Mode 2 (proven feasible):

To docker’s PHP container, under the PHP folder:

If reported/usr/local/bin/docker-php-ext-enable: cannot create/usr/local/etc/php/conf.d/docker-php-ext-pdo_mysql.ini: Directory nonexistent

Solution:

Create conf.d directory and corresponding docker-php-ext-pdo_msql.ini file directly under / usr/local/etc/php directory

The contents of docker-php-ext-pdo_msql.ini are as follows:

extension=pdo_mysql.so

2. Thinkphp error reporting_STORAGE_WRITE_ERROR_:./Application/Runtime/Cache/Home/4e64ea6a2012f26b832b14cbc2152b28.php

Because the server cache folder is not authorized enough, that is, Runtime has no authorization, delete all the cached files, and then give Runtime 777 authorization.

Sudo Chmod 777 Runtime or set 777 permissions directly to the outermost layer of the code base

3. Thinkphp Verification Code Picture does not appear

Lack of GD extension, installation:

The following error may be reported:

Installation:

Re-implement:

Php.ini increases php_gd2.so

Display GD Library in phpinfo

Note that if there is no free type support in phpinfo’s GD library, the validation code will still not be displayed and error will be reported:

Call to undefined function Thinkimagettftext()

If there is no freeType in the GD library, follow the following steps:

If an error is reported:

configure: error: freetype-config not found.

Run: apt-get-y install libfreetype 6-dev, and then continue to run the above command.

If there is a free type in the GD library, the validation code will display normally:

Mysqli Pdo_mysql Docker

The above is the whole content of this article. I hope it will be helpful to everyone’s study, and I hope you will support developpaer more.

Introduction

PDO_MYSQL is a driver that implements the PHP Data Objects (PDO) interface to enable access from PHP to MySQL databases.

PDO_MYSQL uses emulated prepares by default.

MySQL 8

When running a PHP version before 7.1.16, or PHP 7.2 before 7.2.4, set MySQL 8 Server's default password plugin to mysql_native_password or else you will see errors similar to The server requested authentication method unknown to the client [caching_sha2_password] even when caching_sha2_password is not used.

This is because MySQL 8 defaults to caching_sha2_password, a plugin that is not recognized by the older PHP (mysqlnd) releases. Instead, change it by setting default_authentication_plugin=mysql_native_password in my.cnf. The caching_sha2_password plugin will be supported in a future PHP release. In the meantime, the mysql_xdevapi extension does support it.

Warning

Beware: Some MySQL table types (storage engines) do not support transactions. When writing transactional database code using a table type that does not support transactions, MySQL will pretend that a transaction was initiated successfully. In addition, any DDL queries issued will implicitly commit any pending transactions.

Note:

The MySQL driver does not properly support PDO::PARAM_INPUT_OUTPUT via PDOStatement::bindParam(); while such parameters can be used, they are not updated (i.e. the actual output is ignored).

  • Most Viewed News

    • Mastodon Docker Install
    • Teamviewer Mac Os Old Version
    • Macbook Finder
    • Microsoft Office 2019 Mac Free Download