zoukankan      html  css  js  c++  java
  • 基于docker的php调用基于docker的mysql数据库的方法

    1:建立基于docker的mysql,参考

    Mac上将brew安装的MySql改用Docker执行

    2:建立基于docker�php image

    在当前目录,建立Dockerfile,内容如下

    FROM php:7.0-cli MAINTAINER Terry Zhang <zterry@qq.com> RUN docker-php-ext-install pdo_mysql mysqli

    3.建立php镜像

    docker build -t php-mysql .

    4. 编写php脚本,可以从mysql数据库读取数据:

    <?php $host = 'mysql'; $user = 'root'; $pwd = 'password'; $db = 'test'; $mysqli = new mysqli($host, $user, $pwd, $db); if ($mysqli->connect_errno) { echo "Errno: " . $mysqli->connect_errno . " "; } $sql = 'SELECT * FROM users'; if ($res = $mysqli->query($sql)) { while ($row = $res->fetch_assoc()) { print_r($row); } } ?>

    5. 执行php的容器,参数如下: bash docker run -it --rm -v (pwd):/var --link my-mysql-server1:mysql php-mysql:latest php /var/mysql.php

    需要注意的地方是--link参数,这里调用的是名为my-mysql-server1的容器,其在php容器中的host为mysql。可以通过如下命令进行验证:

    docker run -it --rm php-mysql ping mysql

    如果一切顺利,则会看到输出结果;如果有问题,自行调试。

    Then it's just a case of writing the PHP switch statement:

    switch ($getDay) { case 'Monday': $comment = "Worst Day of the Week!"; break; case 'Tuesday': $comment = "1 Day Better Than Monday!"; break; case 'Wednesday': $comment = "Half Way There!"; break; case 'Thursday': $comment = "Getting There!"; break; case 'Friday': $comment = "Weekend At 5pm!"; break; case 'Saturday': $comment = "Relaxing Saturday!"; break; case 'Sunday': $comment = "Work Tomorrow!"; break; }

    The $getDay is the that each case is checked against, and each case is one of the potential values of $getDay . So if it's 'Monday', then the variable will be 'Monday' and that'll match the first case value, so it'll set the variable to the string "Worst Day of the Week!".

    Finally this can be output on the page using:

    echo "Today is " . $getDay . " - " . $comment;

    So this would echo out - Today is Monday - Worst Day of the Week! .

  • 相关阅读:
    ES6展开运算符的10个用法
    用react脚手架新建项目
    第六章 组件 56 组件-组件中的data
    第六章 组件 55 组件-使用components定义私有组件
    第六章 组件 54 组件-创建组件的方式3
    第六章 组件 53 组件-创建组件的方式2
    第六章 组件 52 组件-创建组件的方式1
    第六章 组件 51 组件化和模块化的区别以及组件的定义方式
    第五章 动画 50 动画-transition-group中appear和tag属性的作用
    第五章 动画 49 动画-实现列表删除和删除时候的动画效果
  • 原文地址:https://www.cnblogs.com/2881064178dinfeng/p/6150610.html
Copyright © 2011-2022 走看看