mySQLi bind_param无法正常工作

时间:2019-02-16 21:01:49

标签: mysqli bindparam

我有以下查询:-

public class SceneCreator {

  // launching the new scene based on the .fxml file name passed in the argument as a String variable
  // building the scene and setting the value for the instance variable loader
  public static void launchScene (String sceneName) throws IOException {

    // Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
    FXMLLoader loader = new FXMLLoader(Main.class.getResource(sceneName));
    Main.setRoot(loader.load());
    Scene scene = new Scene(Main.getRoot());
    Main.getStage().setScene(scene);
    Main.getStage().show();



@FXML
  private void sphereClick() throws IOException{
    System.out.println("Sphere button clicked");
    SceneCreator.launchScene("sphere.fxml");
  }

查询工作正常,除了参数绑定。这是我准备好的语句代码:-

SELECT
make_ID,
mileage
FROM cars
WHERE make_ID = ?
ORDER BY ?

第一个绑定$stmt = sqli::$link->prepare($sql); $make_filter = 1; $sort_filter = "mileage"; $stmt->bind_param( 'is', $make_filter, $sort_filter ); $result = array(); // execute query if ($stmt->execute()){ // $stmt->store_result(); // bind results to variables $stmt->bind_result($make, $mileage ); // build results array for return while ($stmt->fetch()){ echo("$make, $mileage<br>"); }; // clear memory $stmt->free_result(); } 可以正常工作,结果仅显示预期的make_ID为WHERE make_ID = ?的行。

但是,第二个绑定1不会基于ORDER BY ?对结果进行排序。我通过删除第二个mileage并像?这样手动输入值来测试SQL,该方法可以正常工作,因此我知道查询没有中断。但是,当尝试绑定值时,排序不起作用。

有人能看到导致问题的代码有什么错误吗?谢谢你的时间。

1 个答案:

答案 0 :(得分:0)

从头开始。经过一些堆栈溢出浏览后,似乎无法绑定列名称,因此ORDER BY将不起作用。

这篇文章帮助我:- Doesn't seem to 'order by' for MySqli Php