无法连接到通过docker-compose创建的MySQL docker容器(Can't connect to MySQL docker container created via docker-compose)
我想开始使用docker并使用nginx容器,PHP-FPM容器和MySQL容器创建一个简单的容器环境。
虽然nginx和PHP-FPM容器之间的链接运行良好,但我似乎无法将PHP应用程序服务器与数据库服务器链接。
我使用docker-compose来最小化手动终端工作。 我的docker-compose.yml看起来像这样:
web: image: tutorial/nginx ports: - "8080:80" volumes: - ./src:/var/www - ./src/vhost.conf:/etc/nginx/sites-enabled/vhost.conf links: - php php: image: nmcteam/php56 volumes: - ./src/php-fpm.conf:/etc/php5/fpm/php-fpm.conf - ./src:/var/www links: - db db: image: sameersbn/mysql volumes: - /var/lib/mysql environment: - DB_NAME=demoDb - DB_USER=demoUser - DB_PASS=demoPass
我尝试使用以下语句连接到DB:
$db = new \PDO('mysql:host=db;dbname=demoName', 'demoUser', 'demoPass');
MySQL容器本身正在工作,因为我可以连接到容器bash并使用MySQL CLI:
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | demoDb | | mysql | | performance_schema | +--------------------+
我只是得到一个500错误,并找不到为什么这不起作用的原因。 任何对我可能错过的帮助或建议都不胜感激。
I want to get started with docker and created a simple container environment with an nginx container, a PHP-FPM container and a MySQL container.
While the link between the nginx and PHP-FPM container works well I can't seem to link the PHP application server with the database server.
I use docker-compose to minimize the manual terminal work. My docker-compose.yml looks like this:
web: image: tutorial/nginx ports: - "8080:80" volumes: - ./src:/var/www - ./src/vhost.conf:/etc/nginx/sites-enabled/vhost.conf links: - php php: image: nmcteam/php56 volumes: - ./src/php-fpm.conf:/etc/php5/fpm/php-fpm.conf - ./src:/var/www links: - db db: image: sameersbn/mysql volumes: - /var/lib/mysql environment: - DB_NAME=demoDb - DB_USER=demoUser - DB_PASS=demoPass
While I try to connect to the DB with the following statement:
$db = new \PDO('mysql:host=db;dbname=demoName', 'demoUser', 'demoPass');
The MySQL container itself is working as I can connect to the containers bash and use the MySQL CLI:
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | demoDb | | mysql | | performance_schema | +--------------------+
I just get a 500 error and can't find a reason why this wouldn't work. Any help or suggestion of what I might have missed is more than appreciated.
原文:https://stackoverflow.com/questions/37463543
最满意答案
缺少分隔符:
preg_match("/^([0-9]{5}|[0-9]{5}\-[0-9]{4})$/", $zip);
Missing delimiters:
preg_match("/^([0-9]{5}|[0-9]{5}\-[0-9]{4})$/", $zip);
相关问答
更多-
is_numeric()测试一个值是否是一个数字。 虽然它不一定是一个整数 - 它可以是十进制数或科学记数法中的数字。 你给出的preg_match()例子只检查一个值是否包含0到9的数字; 它们中的任意数量,以及任何顺序。 请注意,您给出的正则表达式也不是一个完美的整数检查器,就像你写的那样。 它不允许否定; 它确实允许一个零长度的字符串(即根本没有数字,这大概不应该是有效的?),并且它允许该数字具有任意数量的前导零,这也可能不是预期的。 [编辑] 根据您的评论,更好的正则表达式可能如下所示: /^[1- ...
-
使用/(*UTF8)^(([0-8]\d|\d)°?(\s?([0-5]\d|\d))?)(N|S)?$/ 来自http://www.pcre.org/pcre.txt : 为了处理UTF-8字符串,您必须构建具有UTF支持的PCRE的8位库,此外,您必须使用PCRE_UTF8选项标志调用pcre_compile(),或者模式必须以序列(* UTF8)或(* UTF)。 在这些情况中的任何一种情况下,模式和与其匹配的任何主题字符串都被视为UTF-8字符串而不是单个1字节字符的字符串。 因此,PCRE引擎仍然 ...
-
您不需要多次调用preg_match ,只需使用lookahead来强制执行规则,如此正则表达式: ^(?=.*?\d)(?=.*?[a-z])[-\wáàâäãåçéèêëíìîïñóòôöõúùûüýÿæœÁÀÂÄÃÅÇÉÈÊËÍÌÎÏÑÓÒÔÖÕÚÙÛÜÝŸÆŒ0\d!@#$%^&*()+{}:"<>?|\[\];',./\x5c~]{6,30}$ RegEx演示 码: $re = "`^(?=.*?\\d)(?=.*?[a-z])[-\\wáàâäãåçéèêëíìîïñóòôöõúùûüýÿæœ ...
-
使用preg_match php [关闭]将数据输入到单独的索引数组中(Inputting data into separate index array using preg_match php [closed])[2021-12-19]
您没有分配新值。 尝试这个: $new_array[$results] = $away_goals; 然后你可以使用$new_array来获取数据。 You're not assigning a new value. Try this: $new_array[$results] = $away_goals; Then you could use $new_array to get the data afterwards. -
您可以使用此代码: $pattern = <<<'LOD' ~ (?> ### all that you want to skip ### ]*+ > # opening "a" tag (?> [^<]++ | <(?!/a>) )*+ # possible content between "a" tags # closing "a" tag | < ...
-
缺少分隔符: preg_match("/^([0-9]{5}|[0-9]{5}\-[0-9]{4})$/", $zip); Missing delimiters: preg_match("/^([0-9]{5}|[0-9]{5}\-[0-9]{4})$/", $zip);
-
你的PHP匹配字符串是 / ^ \ W {5} $ / 并且PHP匹配字符串由/字符包围,这些字符不是RegEx字符串本身的一部分。 根据评论你的问题是关于理解正则表达式,而不是PHP。 ^是行的开头,正确 $是行的结尾,正确 \ w任何单词字符(字母,数字,下划线) a {5,}表示5个或更多字符'a' 因此:如果用户名中有5个或更多单词字符,则该函数返回肯定结果。 甚至更简单:用户名需要包含至少五个任何单词字符。 详细了解正则表达式及其工作原理。 可以在此评论中找到一些解释。 Your PHP matc ...
-
使用正则表达式更具体,以防止贪婪的表达: preg_match(":vimeo.\w{2,4}/(\d+):i", $url, $vimeoID); Be more specific with your regex to prevent a greedy expression: preg_match(":vimeo.\w{2,4}/(\d+):i", $url, $vimeoID);
-
PHP复杂的preg_match(PHP Complicated preg_match)[2022-03-03]
最好的解决方案可能是使用像DOM DOM Parser这样的DOM解析器库。 但你可以这样做: preg_match('/name="hosted_button_id"\s*value="(\w+)"/', $string, $match); $button_id = $match[1]; The best solution is probably to use a DOM parser library like Simple DOM Parser. But you can do: preg_match( ... -
您在双引号模式中使用美元表达式。 以下为我工作: if(preg_match('/&\$/',trim($lines),$matches)) 检查关于单引号和双引号之间差异的现有问题: PHP中单引号和双引号字符串之间的区别是什么? You are using a dollar expression within the double-quoted pattern. The following works for me: if(preg_match('/&\$/',trim($lines),$matche ...