内爆功能突然停止工作

时间:2017-07-14 15:05:53

标签: php postgresql

这完全正常工作......我对发布帖子的表单上的select语句的where子句进行了一些调整,现在它已不再有效了。知道为什么我突然发生内爆错误吗?

  

警告:implode()[function.implode]:第9行传递的参数无效

  <?php
// show error messages
ini_set('error_reporting', E_ALL);
ini_set("display_errors", 1);

$datea= $_POST["userDatea"];
$media= $_POST["userMedia"];
$datez= $_POST["userDatez"];
$media_names = "'".implode( "%','", $media)."%'";


//var_dump($media_names);

if( !empty($_SERVER['REQUEST_METHOD']) && (strcasecmp($_SERVER['REQUEST_METHOD'], 'post')===0)  ) {
// Create connection
$conn = pg_connect("dbconnection info");

// Check connection
if (!$conn) {
echo "Did not connect.\n";
exit;
}
$result = pg_query($conn,
"SELECT
date (b.starttime),
Count(b.starttime) as Plays,
Count(distinct(b.playerid)) as Stores

FROM
public.billing b,
public.medias m,
public.players p

WHERE
b.mediaitemid = m.id and
p.id = b.playerid and
m.name LIKE any (array[$media_names]) and
b.starttime >= date('$datea') and 
b.starttime < date('$datez')+1 and
m.startdate >  '2015-01-01'

GROUP BY
date (b.starttime)

ORDER BY
date (b.starttime);");

if (!$result) {
  echo "Query failed.\n";

  exit;
}

 $num_fields = pg_num_fields($result);
    $headers = array();

    for ($i = 0; $i < $num_fields; $i++) 
    {
        $headers[] = pg_field_name($result , $i);
    }

    $fp = fopen('php://output', 'w');
    if ($fp && $result)
    {
            header('Content-Type: text/csv');
            header('Content-Disposition: attachment; filename="customreport.csv"');
            header('Pragma: no-cache');
            header('Expires: 0');
            fputcsv($fp, $headers);

            while ($row = pg_fetch_row($result)) 
            {
                 fputcsv($fp, array_values($row));
            }
            die;

}
        exit('It works');
    }
?>

这是帖子的来源:

<select multiple name="userMedia" class="form-control" id="userMedia[]" style="height:350px;">
 <?php

$conn = pg_connect("db connection");

if (!$conn) {
echo "Did not connect.\n";
exit;
}
$sql = "SELECT 
        m.name
        FROM 
        public.medias m
        where 
        date(m.enddate) >= date(now()) - interval '183 days' and
        date(m.startdate) > '2015-01-01' and
        m.enddate != ''

        UNION ALL

        SELECT 
        m.name
        FROM 
        public.medias m
        where 
        m.enddate = '' and
        date(m.startdate) > '2015-01-01';";
$rs = pg_query($conn, $sql);


if (pg_num_rows($rs) > 0) {
// output data of each row
while($row = pg_fetch_assoc($rs)) {
$menu .= "<option value=".$row['name'].">" . $row['name']. "</option>";
}
}

echo $menu;

pg_close($conn); 

?> 
</select></p>

1 个答案:

答案 0 :(得分:0)

由于您传递给implode()的第一个参数是一个字符串(“胶水”),因此它希望第二个参数为array

$media(使用$_POST["userMedia"]初始化)不是数组时,implode()会触发警告并返回NULL而不是您期望的字符串。