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

时间:2013-07-15 17:16:35

标签: 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,则会出现空白屏幕。我没有得到这个代码的错误吗?任何人都可以帮我识别错误吗?

1 个答案:

答案 0 :(得分:0)

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