0

我有 1 个数据库。我有一个表。我正在这段代码中进行 json 解析。
我已经使用这个 php 代码来检索值:

<head>
<style type="text/css">
.auto-style1 {
    text-align: right;
}
</style>
</head>

<?php

echo getdata($_REQUEST['lastupdate']);

function getdata($lastupdatedate){


    $obj = json_decode($json);



    $con = mysql_connect("localhost","root","Password");


    if (!$con)
    {
        die('Could not connect: ' . mysql_error());
    }
    mysql_select_db("roster", $con);

    $query = "select * from statedeathtax_v2 where LastUpdated > '".$lastupdatedate."' order by LastUpdated";

    $rs = mysql_query($query) or die($query);

    //print_r($rs);

    while($row=mysql_fetch_assoc($rs)){

    $record[] = $row;

    }



    $data = json_encode($record);



    header('Cache-Control: no-cache, must-revalidate');

    header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');

    header('Content-type: application/json');

    return $data;

}

?>

此处代码不显示“$”等特殊字符。当我在这段代码中抛出查询时,它显示具有特殊字符的列的空值。我没有得到这个问题。

4

2 回答 2

0

我已经解决了问题:

更新代码:

<?php

echo getdata($_REQUEST['lastupdate']);

function getdata($lastupdatedate){


    $obj = json_decode($json);



    $con = mysql_connect("localhost","root","Password@123");
    mysql_set_charset('utf8',$con);

    if (!$con)
    {
        die('Could not connect: ' . mysql_error());
    }
    mysql_select_db("roster", $con);

    $query = "select * from statedeathtax_v2 where LastUpdated > '".$lastupdatedate."' order by LastUpdated";

    $rs = mysql_query($query) or die($query);

    //print_r($rs);

    while($row=mysql_fetch_assoc($rs)){

    $record[] = $row;

    }



    $data = json_encode($record);



    header('Cache-Control: no-cache, must-revalidate');

    header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');

    header('Content-Type: application/json; charset=utf-8' );

    return $data;

}

?>
于 2012-11-08T12:11:33.987 回答
0

对于 mysqli_connect:

$conecta = mysqli_connect("host", "user", "pass", "dbase") 
or print (mysql_error()); 

$conecta->set_charset('utf8');

检查更多 http://dev.mysql.com/doc/apis-php/en/apis-php-mysqlinfo.concepts.charset.html

于 2015-02-04T02:32:31.930 回答