gpt4 book ai didi

php mysql 初学者 echo MySQL 查询

转载 作者:行者123 更新时间:2023-11-29 12:12:11 27 4
gpt4 key购买 nike

我想计算行数并打印 php echo。但是当我回显查询时,它显示:资源 id #5。但它必须只显示数字 5。

<?php 
$db=require "script_database/connect.php";
$query="select count(name) from selection where salary>2000 and job='teacher' ";
$key=mysql_query($query);
echo $key;
if(key>0)
{

echo "no row found";

}
?>

最佳答案

mysql_query 将返回执行查询的资源,而不是数据。你必须获取它 -

    $query="select count(name) from selection where salary>2000 and job='teacher' ";
$result=mysql_query($query);
$key = mysql_fetch_array($result);
echo $key['count(name)'];

mysql is deprecated now. Use mysqli or PDO instead.

返回

For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.

For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error.

The returned result resource should be passed to mysql_fetch_array(), and other functions for dealing with result tables, to access the returned data.

Use mysql_num_rows() to find out how many rows were returned for a SELECT statement or mysql_affected_rows() to find out how many rows were affected by a DELETE, INSERT, REPLACE, or UPDATE statement.

mysql_query() will also fail and return FALSE if the user does not have permission to access the table(s) referenced by the query.

关于php mysql 初学者 echo MySQL 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30449994/

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