doxrxwn2252 2015-04-02 02:32
浏览 34
已采纳

尝试使用php从mysql中选择记录,结果是在没有标识符的json中

As mentioned, I am getting a JSON string with out the identifiers. The code I am using is:

<html>
    <head>
        <script language="javascript" type="text/javascript" src="/content/scripts/jquery/v2.1.3/jquery-2.1.3.js"></script>
    </head>
    <body>
        <h2> Client example </h2>
        <h3>Output: </h3>
<?php
    $host = "localhost";
    $user = "{username}";
    $pass = "{password}";
    $databaseName = "{database}";
    $tableName = "{table}";

    $con = mysql_connect($host,$user,$pass);
    $dbs = mysql_select_db($databaseName, $con);

    $result = mysql_query("SELECT * FROM $tableName");
    $array = mysql_fetch_row($result);

    echo json_encode($array);
?>
</body>

My results are:

["2d791c8b-d8cf-11e4-a712-002590f3d888","********","********"]

I am extremely new to PHP and MySQL, so be gentle.

  • 写回答

2条回答 默认 最新

  • duanaoshu1989 2015-04-02 04:53
    关注

    mysql_fetch_row returns an enumerated array

    [0] => "2d791c8b-d8cf-11e4-a712-002590f3d888"
    

    mysql_fetch_array returns an associative array

    ["key"] => "2d791c8b-d8cf-11e4-a712-002590f3d888"
    

    mysql_* functions are now defunct, preceded with MySQLi/PDO.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器