在PHP脚本中设置lc_time_names没有响应

时间:2017-06-27 03:16:13

标签: php mysql

我正在尝试更改my(mysql)数据库中time names列的date

当我在phpMyAdmin中运行以下语句时,我得到了正确的响应

set lc_time_names = 'nl_NL'; SELECT id, name, date_format(date1, '%e %M %Y') AS date1, date_format(date2, '%e %M %Y') AS date2 FROM `users`

当我尝试在我的PHP脚本中运行此语句时,我得不到任何响应。这是我的PHP脚本的一部分:

$sql = "set lc_time_names = 'nl_NL'; SELECT id, name, date_format(date1, '%e %M %Y') AS date1, date_format(date2, '%e %M %Y') AS date2 FROM `users` ";
$sqlTot .= $sql;
$sqlRec .= $sql;
//concatenate search sql if value exist
if(isset($where) && $where != '') {

    $sqlTot .= $where;
    $sqlRec .= $where;
}

有人知道什么是错的以及我如何解决它?

当我运行没有set lc_time_names = 'nl_NL';的语句时,PHP脚本正在响应。

修改1:

$sql = "set lc_time_names = 'nl_NL'; ";
$sql .= "SELECT id, name, date_format(date1, '%e %M %Y') AS date1, date_format(date2, '%e %M %Y') AS date2 FROM `users` ";
$sqlTot .= $sql;
$sqlRec .= $sql;
//concatenate search sql if value exist
if(isset($where) && $where != '') {

    $sqlTot .= $where;
    $sqlRec .= $where;
}


$sqlRec .=  " ORDER BY ". $columns[$params['order'][0]['column']]."   ".$params['order'][0]['dir']."  LIMIT ".$params['start']." ,".$params['length']." ";

$queryTot = mysqli_multi_query($conn, $sqlTot) or die("database error:". mysqli_error($conn));


$totalRecords = mysqli_num_rows($queryTot);

$queryRecords = mysqli_multi_query($conn, $sqlRec) or die("error to fetch employees data");

//iterate on results row and create new index array of data
while( $row = mysqli_fetch_row($queryRecords) ) { 
    $data[] = $row;
}   

$json_data = array(
        "draw"            => intval( $params['draw'] ),   
        "recordsTotal"    => intval( $totalRecords ),  
        "recordsFiltered" => intval($totalRecords),
        "data"            => $data   // total data array
        );

echo json_encode($json_data);  // send data as json format

1 个答案:

答案 0 :(得分:0)

连接字符串如下:

$conn = mysqli_connect($servername, $username, $password, $dbname) or die("Connection failed: " . mysqli_connect_error());

我通过在连接字符串后添加查询来解决问题:

$conn = mysqli_connect($servername, $username, $password, $dbname) or die("Connection failed: " . mysqli_connect_error());
$conn->query("SET lc_time_names = 'nl_NL'");