doxrxwn2252 2015-04-01 18: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-01 20: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 DevEco studio开发工具 真机联调找不到手机设备
  • ¥15 请教前后端分离的问题
  • ¥100 冷钱包突然失效,急寻解决方案
  • ¥15 下载honeyd时报错 configure: error: you need to instal a more recent version of libdnet
  • ¥15 距离软磁铁一定距离的磁感应强度大小怎么求
  • ¥15 霍尔传感器hmc5883l的xyz轴输出和该点的磁感应强度大小的关系是什么
  • ¥15 vscode开发micropython,import模块出现异常
  • ¥20 Excel数据自动录入表单并提交
  • ¥30 silcavo仿真,30分钟,只需要代码
  • ¥15 FastReport 怎么实现打印后马上关闭打印预览窗口