gpt4 book ai didi

php - 选择 * 不会在 php mysql 中打印任何内容

转载 作者:搜寻专家 更新时间:2023-10-30 21:44:51 25 4
gpt4 key购买 nike

我制作了一个 php 脚本,如下所示运行它,输出是记录添加到表中

<?PHP

$user_name = "root";
$password = "";
$database = "test_db";
$server = "127.0.0.1";
$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);

if ($db_found) {

$SQL = "INSERT INTO name (FirstName) VALUES ('bill')";
$result = mysql_query($SQL);

mysql_close($db_handle);

print "Records added to the database";
}
else {
print "Database NOT Found ";
mysql_close($db_handle);
}

?>

现在看看我做的表的内容

<?PHP

$user_name = "root";
$password = "";
$database = "test_db";
$server = "127.0.0.1";
$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);

if ($db_found) {

$SQL = "Select * from name";
$result = mysql_query($SQL);

print "$result";
mysql_close($db_handle);

print "Records added to the database";
}
else {
print "Database NOT Found ";
mysql_close($db_handle);
}

?>

但是输出的是Resource id #3Records added to the database,而我想看表的内容

最佳答案

mysql_query 的返回值无法像您尝试的那样发送到输出。

mysql_query 返回一个结果集,用于 http://www.php.net/mysql_fetch_row例如。

例子:

while($row=mysql_fetch_array($result)) {
print_r($row);
}

关于php - 选择 * 不会在 php mysql 中打印任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5722713/

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