PHP PDO 如何运行多个查询请求?

2024-01-07

你好,我正在尝试在 PHP 中执行此 SQL 请求PDOStatement:

CREATE TEMPORARY TABLE r1
SELECT CONCAT(MONTH(Heure_deb),'/',DAY(Heure_deb)) as 'Date',
                      Heure_deb,
                      Operateur.Id_op ,
                      Nom_op ,
                      Prenom_op,
                      Nom_act ,
                      TIME(Heure_deb) as heure,
                      Commentaire,
                      Type
                      FROM Operateur, Pointage, Activite
                      WHERE Operateur.Id_op = Pointage.Id_op
                      AND Activite.Id_act = Pointage.Id_act
                      ORDER BY date, Id_op, heure
;
Create temporary table r2
SELECT a.Id_op, a.Heure_deb, MIN(b.heure_deb) as fin, TIMEDIFF(b.Heure_deb, a.Heure_deb) as Time_Difference, ROUND(HOUR(TIMEDIFF(b.Heure_deb, a.Heure_deb)) + MINUTE(TIMEDIFF(b.Heure_deb, a.Heure_deb))/60,2) as Decimal_duree
FROM Pointage a
LEFT JOIN Pointage b ON a.Id_op = b.Id_op
WHERE a.heure_deb < b.heure_deb
Group by a.Id_op, a.Heure_deb
;
select CONCAT(MONTH(r1.Heure_deb),'/',DAY(r1.Heure_deb)) as 'Date',
                      TIME(r1.Heure_deb) as heure,
                      r1.Id_op ,
                      Nom_op ,
                      Prenom_op,
                      Nom_act ,
                      Commentaire,
                      Type,
                      Time_Difference,
                      Decimal_duree
from r1
LEFT JOIN r2 ON r1.Id_op = r2.Id_op and r1.heure_deb = r2.heure_deb
Order by Id_op, Date , heure

此请求在 phpMyAdmin 中返回此内容Request https://i.stack.imgur.com/7Kc1q.png

但在 PHP 中,获取不起作用,返回 false 但任何错误代码。 PHP代码:

  $result=$objPdo->prepare($requete);
  $result->execute();
  $err = $result->errorInfo();
  if(!empty($err[2])){
  echo"<script type='text/javascript'>alert('Erreur SQL :".$err[2]."');</script>";
  }else{
  while($row=$result->fetch()){
    echo"<tr>
              <td>".$row['Date']."</td>
              <td>".$row['heure']."</td>
              <td>".$row['Nom_op']."</td>
              <td>".$row['Prenom_op']."</td>
              <td>".$row['Type']."</td>
              <td>".$row['Time_Difference']."</td>
              <td>".$row['Decimal_duree']."</td>
              <td>".$row['Commentaire']."</td>
          </tr>";
  }
  echo"</table></div>";
}

此请求中有三个查询,因此您必须在以下位置运行它们three来电,没有一个:

$objPdo->query("CREATE TEMPORARY TABLE r1
SELECT CONCAT(MONTH(Heure_deb),'/',DAY(Heure_deb)) as 'Date',
                      Heure_deb,
                      Operateur.Id_op ,
                      Nom_op ,
                      Prenom_op,
                      Nom_act ,
                      TIME(Heure_deb) as heure,
                      Commentaire,
                      Type
                      FROM Operateur, Pointage, Activite
                      WHERE Operateur.Id_op = Pointage.Id_op
                      AND Activite.Id_act = Pointage.Id_act
                      ORDER BY date, Id_op, heure
;";

$objPdo->query("Create temporary table r2
SELECT a.Id_op, a.Heure_deb, MIN(b.heure_deb) as fin, TIMEDIFF(b.Heure_deb, a.Heure_deb) as Time_Difference, ROUND(HOUR(TIMEDIFF(b.Heure_deb, a.Heure_deb)) + MINUTE(TIMEDIFF(b.Heure_deb, a.Heure_deb))/60,2) as Decimal_duree
FROM Pointage a
LEFT JOIN Pointage b ON a.Id_op = b.Id_op
WHERE a.heure_deb < b.heure_deb
Group by a.Id_op, a.Heure_deb
;";

$result = $objPdo->query("select CONCAT(MONTH(r1.Heure_deb),'/',DAY(r1.Heure_deb)) as 'Date',
                      TIME(r1.Heure_deb) as heure,
                      r1.Id_op ,
                      Nom_op ,
                      Prenom_op,
                      Nom_act ,
                      Commentaire,
                      Type,
                      Time_Difference,
                      Decimal_duree
from r1
LEFT JOIN r2 ON r1.Id_op = r2.Id_op and r1.heure_deb = r2.heure_deb
Order by Id_op, Date , heure";

while($row=$result->fetch()){
    echo"<tr>
          <td>".$row['Date']."</td>
          <td>".$row['heure']."</td>
          <td>".$row['Nom_op']."</td>
          <td>".$row['Prenom_op']."</td>
          <td>".$row['Type']."</td>
          <td>".$row['Time_Difference']."</td>
          <td>".$row['Decimal_duree']."</td>
          <td>".$row['Commentaire']."</td>
      </tr>";
}
echo"</table></div>";
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

PHP PDO 如何运行多个查询请求? 的相关文章

  • Zend 框架会话丢失

    我有一个注册表单 当用户注册时 它会将他重定向到他的页面 在 Firefox 和 Chrome 中一切正常 但在 Internet Explorer 中则正常 看起来保存用户信息后 会话就关闭了 并且不会将用户重定向到他的页面 我该如何解决
  • phpenmod 显示其他 php 版本的路径

    我的 Ubuntu 机器上安装了 php 7 0 和 7 2 当我执行时php v 它告诉我我正在使用 php 7 2 在 Apache 上我还启用了 php 7 2 当我跑步时phpenmode zip 我明白了 WARNING Modu
  • PHP 多个 Ajax 请求:第一个请求阻止第二个请求

    我在一页上有 2 个 ajax 请求 我运行了第一个请求并单独启动了第二个请求 但第二个在第一个运行后停止工作 第一次结束后继续 第一个请求需要很长时间 大约 30 60 秒 此时我需要第二个请求来显示日志第一个请求发生的情况 我尝试使用
  • 如何使用 Google Calendar API 和官方 PHP 库创建全天活动?

    我有这个代码 event new Event event gt setSummary event summary event gt setLocation event location start new EventDateTime sta
  • FPM 与 apache2 无法工作(权限被拒绝)

    我正在尝试使用 apache fastcgi 和 fpm 设置一个 Debian Web 服务器 但我越来越恼火 一旦我停用 mod php 我就会收到以下错误 2014 年 5 月 22 日星期四 12 16 10 错误 客户端 xxx
  • MySql 从另一个表中减去一个表

    我有两个表 A 包含所有数据 表 B 从 A 中随机选择 25 的数据创建 所以 A 和 B 具有完全相同的列 也没有独特的列 我想做的是从 A 中减去 B 有什么想法吗 查看所有行A除了那些在B SELECT FROM A WHERE f
  • PHP、PDO 和 SQLSRV 对一个 INSERT 语句执行多次

    我已经在 MySQL 和 Apache 服务器上使用 PDO 和 PHP 一段时间了 我最近的任务是将企业的旧 Web 应用程序转换为新设置 旧设置是标准 Linux Web 堆栈 Apache PHP MySQL Filezilla 新设
  • PHP 何时实现了函数使用闭包? [复制]

    这个问题在这里已经有答案了 我在 PHP 手册中找不到解释的部分use 我有代码 num 0 array walk recursive REQUEST function mValue use num num 我的 Eclipse 抱怨 Pa
  • PHP 中正确的存储库模式设计?

    前言 我尝试在具有关系数据库的 MVC 架构中使用存储库模式 我最近开始学习 PHP 中的 TDD 并且我意识到我的数据库与应用程序的其余部分耦合得太紧密 我读过有关存储库并使用国际奥委会容器 http laravel com docs 4
  • Google Drive V3、Google API 客户端 2.0 - 批量上传失败

    使用 Google Drive V3 和 API v2 0 主分支进行批量上传失败 我已经修改了https github com google google api php client blob master examples batch
  • MySQL 选择第一个字符在哪里

    如何选择单元格的第一个字符并使用它来定义返回的内容 看看MySQL 字符串 和 控制流 功能 http dev mysql com doc refman 5 1 en functions html 例如 SELECT IF LEFT myF
  • 什么是 PHP session_start()

    它是否基于 cookie 启动当前会话 从 PHP 网站上得到的 PHP如何控制会话 如果我在用户打开我的登录页面时启动会话 我什至可以使用该会话做什么 我可以使用当前会话来获取有关登录用户的信息吗 PHP 会话系统允许您将数据安全地存储在
  • MySQL 和 MariaDB 数据库有什么区别?

    我已经使用 XAMPP 很长时间了 很惊讶 XAMPP 已经从 MySQL 切换到了 MariaDB https www apachefriends org index html https www apachefriends org in
  • 如何告诉node.js mysql没有在默认端口上运行?

    我遇到了与此人类似的问题 连接 ECONNREFUSED 节点 js sql https stackoverflow com questions 8825342 connect econnrefused node js sql 我正在尝试将
  • 将 docker-compose.yml 中的包安装到 docker 容器中

    我是 docker 和 docker compose 的初学者 我需要你的帮助 我正在使用 docker compose 制作 PHP NGINX PostgresQL symfony 开发环境 这里是 web image nginx 1
  • 安装后步骤未成功完成 MySQL Mac OS Sierra

    pyEnv Anants MacBook Pro litibackend anantchandra brew postinstall mysql gt Postinstalling mysql gt usr local Cellar mys
  • Yii2 无效调用:设置只读属性

    我有一个Post具有多对多关系的模型Tags 在 Post 模型中定义 public function getTags return this gt hasMany Tags className id gt tag id gt viaTab
  • 在 Elasticsearch php API 中使用多种类型或索引

    我想使用查询多种类型和索引Elasticsearch PHP API 但我不知道怎么办 我应该将类型和索引的数组传递给 params params index index array of indices params type types
  • 如何强制下载图片?

    我的页面上有一个动态生成的图像 如下所示 img src 我不想告诉我的用户右键单击图像并点击保存 而是想公开一个下载链接 单击该链接将提示下载图像 如何实现这一目标 最初我在 js 中尝试这样做 var path my image att
  • 突出显示单词并提取其附近文本的函数

    我有一个文本例如 Etiam porta semmalesuada magna mollis euismod 整数取数 ante venenatis dapibus posuere velit aliquet 埃蒂亚姆 门塔 塞姆 male

随机推荐