php - 以下 PHP MySQL 代码有什么问题?

标签 php mysql database database-connection

我正在使用 PHP 和 MySQL 数据库。

    $con=mysql_connect("localhost","XYZ","pqr") or die("Failed to connect with database!!!!");
    mysql_select_db("LMN", $con); 

    //Code and SQL query to find out the User transactions count of all types from beginning till today's date
    $sql  =" SELECT COUNT(*) `carried out`, SUM(transaction_status = 'success') `success`, ";
    $sql .=" SUM(transaction_status = 'inprocess') `inprocess`, SUM(transaction_status = 'fail') `fail`, ";
    $sql .=" SUM(transaction_status = 'cancelled') `cancelled` FROM OCN.user_transaction ";



    $result = mysql_query($con,$sql);
echo $result; die;  

    $r =  mysql_fetch_array($result);

如果我要echo $result,则会出现空白屏幕。我不明白这段代码有什么问题?任何人都可以帮助我识别错误吗?

最佳答案

$result = mysql_query($sql) or die(mysql_error());
$r = mysql_fetch_array($result, MYSQL_ASSOC);
print_r($r);

关于php - 以下 PHP MySQL 代码有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17659970/

相关文章:

php - Crontab:PHP Wget 或 Curl

php - Tcpdf 单页多个书签

javascript - 将变量从脚本替换为同一页面上的另一个变量(JS/PHP)

php - 从 MySQL 数据库中的数组分配变量

php - 连接 MySQL 信息和 2 个表

mysql - MyISAM 与 InnoDB

mysql - 如何从表中获取最低值

java - org.hibernate.HibernateException : Unable to access lob stream

php - 如何从php中的sha1()获取加密字符的原始字符串?

mysql - 在 MySQL 列中搜索相似词