如何在PDO语句中使用变量?

时间:2016-12-28 21:54:10

标签: php mysql sql variables pdo

我已经尝试了几天从数据库中根据变量对某些“产品”进行排序,我无法弄清楚这一点。我尝试了所有不同的方法,但它们不起作用。这是我到目前为止,我是这个主题的新手,所以我将不胜感激。

$resultsall = $conn->prepare("SELECT productName, productVendor, SUBSTRING(productDescription, 1, 150), quantityInStock, buyPrice, productcat, MSRP FROM products LEFT JOIN productlines ON products.productLine = productlines.productLine ORDER BY :orderby");
    $orderby = "buyPrice";
    $resultsall->bindParam(':orderby', $orderby, PDO::PARAM_STR);
    $resultsall->execute();

0 个答案:

没有答案