【问题标题】:print_r SQL statement [closed]print_r SQL 语句 [关闭]
【发布时间】:2016-03-16 15:56:57
【问题描述】:

我正在尝试打印一条 SQL 语句,但我不确定我是否正确地执行它。它不会打印任何结果,只是简单地打印 SQL 语句本身。

<?php

    $date = new DateTime();
    $ts = $date->getTimestamp();

    $currentDate = strtotime(date("Y-m-d", $ts));


    $sql = "SELECT * FROM 'events' where 'date_start' = '$currentDate'";

    print_r($sql);

?>  

【问题讨论】:

标签: php sql unix-timestamp


【解决方案1】:
$sql = "SELECT * FROM 'events' where 'date_start' = '$currentDate'";


$result= mysql_query($sql) or die(mysql_error());


print_r($result);

使用 mysql_query 现在试试希望这会有所帮助:)

【讨论】:

  • 谢谢大家!
  • 请不要建议人们使用mysql_函数。该库已弃用,并已从最新版本的 PHP 中删除
【解决方案2】:

从表名和列名中删除单个配额',或替换为(`):

$sql = "SELECT * FROM events where date_start = '$currentDate'";

或:

$sql = "SELECT * FROM `events` where `date_start` = '$currentDate'";

【讨论】:

    【解决方案3】:

    那是因为查询还没有执行。

    您需要使用 mysql_query 或 mysqli_query(您使用的任何一个)来执行它,然后获取结果。

    $sql     = "SELECT * FROM events where date_start = '".$currentDate"' ";
    $result  = mysql_query($sql) or die(mysql_error());
    $result  = mysqli_query($sql) or die(mysqli_error($con));
    print_r($result  );
    

    希望这会有所帮助。

    和平! xD

    【讨论】:

      【解决方案4】:

      如果您的时间是整数,则可以使用它。

      <?php
      
              $date = new DateTime();
              $ts = $date->getTimestamp();
      
              $currentDate = strtotime(date("Y-m-d", $ts));
      
      
             $sql = "SELECT * FROM events where date_start = '$currentDate'";
      
              print_r($sql);
      
          ?>  
      

      【讨论】:

      • 他想运行查询。你的答案没有这样做。
      猜你喜欢
      • 2021-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-09
      • 2021-11-03
      • 2011-12-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多