gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 22:39:57 25 4
gpt4 key购买 nike

如上所述,我得到了一个不带标识符的 JSON 字符串。我使用的代码是:

<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>

我的结果是:

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

我对 PHP 和 MySQL 非常陌生,所以要温柔。

最佳答案

mysql_fetch_row 返回枚举数组

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

mysql_fetch_array 返回关联数组

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

mysql_* 函数现已失效,之前有 MySQLi/PDO。

关于php - 尝试使用php从mysql中选择记录,结果是没有标识符的json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29404092/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com