簡體   English   中英

查詢未插入,但也不給出錯誤

[英]Query not inserting, but not giving error either

我得到了這個查詢,它沒有插入數據庫,但也沒有給出錯誤。

        try {
        $sth = $Db->dbh->prepare("INSERT INTO users (username,password,email,phone,first_name) VALUES (:username,:password,:email,:phone,:firstname)");
        $sth->execute(array(':username' => $username,':password' => $password, ':email' => $email,':phone' => $phone,':firstname'=>$firstname));
    } catch(Exception $e) {
        echo $e->getMessage();
        exit();
    }

在此處輸入圖片說明 我試過通過命令插入查詢,它工作正常。 該網站上還有其他插入查詢,這些查詢也可以正常工作。.我不確定我在做什么錯

你可以嘗試這樣的事情嗎?

try
{
    // Prepare Statement
    if (!($stmt = $mysqli->prepare("INSERT INTO users (username,password,email,phone,first_name) VALUES (?,?,?,?,?)")))
        throw new Exception("Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error);

    // Bind Parms
    if (!$stmt->bind_param("sssss", $username, $password, $email, $phone, $firstname))
        throw new Exception("Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error);

    // Execute Statement
    if (!$stmt->execute())
        throw new Exception("Execute failed: (" . $stmt->errno . ") " . $stmt->error);
}
catch (Exception $ex) {
    exit('Error: '. $ex->getMessage());
}

PS至於TiiJ7對你的問題的意見建議,是那些兩列permrank -他們nullable列? 如果不是,則可能必須在插入行時指定一個值。

此處的更多信息: http : //php.net/manual/en/mysqli.quickstart.prepared-statements.php

暫無
暫無

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

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