簡體   English   中英

如何獲取帶有綁定變量的where子句以在php中工作

[英]How to get the where clause with a bind variable to work in php

function get_grade($sku) {
    require("config.php");
    try {

        $results = $db -> query prepare ("SELECT name, subject1,grade1,attendance,gender,subject2,grade2,subject3,grade3 FROM student WHERE sku = ?"); //binds the sku to the question mark
        $results -> bindParam;
        $results -> execute();
    }
    catch exception ($e) {
        echo "could not connect";
        exit;
    }
    $product = $results-> fetch (PDO::FETCH_ASOC);
}

如何獲得where子句,如果用戶的出勤率,科目和成績相同或相似,則他們將在哪里獲得,然后他們將從過去的學生那里獲得該成績。

您需要綁定$sku

$results->bindParam(1, $sku);

這應該為您工作:

function get_grade($sku) {
    require("config.php");

    try {

        $results = $db->prepare("SELECT name, subject1,grade1,attendance,gender,subject2,grade2,subject3,grade3 FROM student WHERE sku = :sku"); 
                     //^^^^^^^^Perpare statement here                                                                                  //^^^^Placeholder for variable
        $results->execute(array("sku" => $sku));
                        //^^^^^^^^^^^^^^^^^^^Instead of binParam

    } catch (PDOException $e) {
           //^^^^^^^^^^^^^^^ Catch PDO exeption
        echo $e->getMessage();
        exit;
    }
    $product = $results->fetch(PDO::FETCH_ASOC);


}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM