SELECTi DISTINCT在mysqli中准备的语句? [英] SELECT DISTINCT in mysqli prepared statement?

查看:72
本文介绍了SELECTi DISTINCT在mysqli中准备的语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将mysql函数转换为mysqli准备好的语句.

I am trying to convert a mysql function into mysqli prepared statement.

但是,我在使其工作,尤其是选择独特产品方面遇到问题.

however, I have problems getting it to work especially the select distinct.

mysql函数中的select different与mysqli准备好的语句之间有什么区别吗?

is there any difference between select distinct in mysql function and mysqli prepared statement?

这有效:

    $sql = "SELECT DISTINCT category FROM $storeShop";

    $result = mysql_query($sql) or die("Query failed : " . mysql_error());

    // For each result that we got from the Database
    while ($line = mysql_fetch_assoc($result))
    {
     $cvalue[] = $line;
    }
    // Assign this array to smarty...

    $smarty->assign('category', $cvalue);
// Assign this array to smarty...
$smarty->assign('$category', $cvalue);

这不起作用:

    $stmt = mysqli_prepare($db_conx, "SELECT DISTINCT category FROM $storeShop");
     $stmt->execute();
    $stmt->bind_result($category);

    /* fetch values */

    while ($line = ($stmt->fetch())) {
        $cvalue[] = $line;

    }

    // Assign this array to smarty...

    $smarty->assign('category', $cvalue);



  // Assign this array to smarty...
    $smarty->assign('$category', $cvalue);

我准备好的语句代码中缺少任何内容吗?我需要怎么做才能使其正常工作?

am I missing anything in my prepared statement code? and what do I need to do to make it work?

谢谢.

这也可以,但是它不是准备好的语句:

This works as well but it is not prepared statement:

$sql = "SELECT DISTINCT category FROM $storeShop";
$query = mysqli_query($db_conx, $sql);
$productCount = mysqli_num_rows($query); // count the output amount
    while($line = mysqli_fetch_array($query, MYSQLI_ASSOC)){
        $cvalue[] = $line;
    }

推荐答案

mysql函数中的select different与mysqli准备好的语句之间有什么区别吗?

is there any difference between select distinct in mysql function and mysqli prepared statement?

很明显,没有.
API语法与SQL语法完全无关.

Obviously, no.
API syntax has absolutely nothing to do with SQL syntax.

您的问题在其他地方.您需要学习调试应用程序,以使自己了解真实的原因,并最终能够针对实际问题发布问题,而不是盲目地戳.您可以从这里开始: https://stackoverflow.com/a/22662582/285587

Your problem is somewhere else. You need to learn to debug your application to make yourself aware of the real cause and eventually be able to post a question on the real problem you have, instead of blindly poking by chance. You may start here: https://stackoverflow.com/a/22662582/285587

这篇关于SELECTi DISTINCT在mysqli中准备的语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆