簡體   English   中英

PDO查詢未插入且未引發錯誤

[英]PDO query not inserting and not throwing errors

我正在將數據插入表中,並使用PDO更新數據庫中的表,但我當然不是最了解。

我使用的是我過去使用過很多次的語句,但是由於某種原因,這一次對准備好的插入語句不起作用。 它僅適用於update語句。

聲明如下:

        error_reporting(E_ALL);
        ini_set('display_errors',1); 
        //fetching error
        $stmt = $pdo->prepare("INSERT INTO tb_beli (username, bank, norek, nama, ec, bitcoin, perfectmoney, fasapay, paket, saldo, amountbtc, phone, email, status, referer, iddb, date, ip, exp, unik,idph, upline, token) 
        VALUES(:username, :bank, :norek, :nama, :ec,  :bitcoin, :perfectmoney, :fasapay, :paket, :saldo, :amountbtc, :phone, :email, :status, :referer, :iddb, :date, :ip, :exp, :unik, :idph, :upline, :token)");
        $stmt ->execute(array(':username' => $kuriree, ':bank' => $bankee, ':norek' => $norekee, ':nama' => $namaee, ':ec' => $matauang,  ':bitcoin' => $bitcoinee, ':perfectmoney' => $pmee, ':fasapay' => $fasapayee, ':paket' => $paketzee, ':saldo' => $surabayae, ':amountbtc' => $convertbtc2, ':phone' => $phoneee, ':email' => $emailee, ':status' => $status1,':referer' => $kurirz,':iddb' => $idnyaz,':date' => $skrg,':ip' =>$laip ,':exp' => $exp,':unik' => $unikee,':idph' => $idnyaee,':upline' => $mangkosim,':token' => $unikeef ));
        //
        //echo  done  
        $stmt = $pdo->prepare("INSERT INTO tb_jual (username, bank, norek, nama, ec,  bitcoin, perfectmoney, fasapay, paket, saldo, amountbtc, phone, email, status, date, ip, idgh, token) 
        VALUES(:username, :bank, :norek, :nama, :ec,  :bitcoin, :perfectmoney, :fasapay, :paket, :saldo, :amountbtc, :phone, :email, :status, :date, :ip, :idgh, :token)");
        $stmt ->execute(array(':username' => $kurirz, ':bank' => $bankeem, ':norek' => $norekeem, ':nama' => $namaeem, ':ec' => $matauang,  ':bitcoin' => $bitcoineem, ':perfectmoney' => $pmeem, ':fasapay' => $fasapayeem, ':paket' => $paketzee, ':saldo' => $surabayae, ':amountbtc' => $convertbtc2, ':phone' => $phoneeem, ':email' => $emaileem, ':status' => $status2, ':date' => $skrg, ':ip' => $laip, ':idgh' => $idnyaz, ':token' => $unikeef));
        //
        //echo  done  
        $stmt= $pdo->prepare("UPDATE tb_ph SET saldo= (saldo - :saldo) where id=:id ");
        $stmt ->execute(array(':id' => $idnyaee, ':saldo' => $surabayae)); 
        //
        //echo  done  
        $stmt= $pdo->prepare("UPDATE tb_gh SET saldo= (saldo - :saldo) where id=:id");
        $stmt->execute(array(':id' => $idnyaz , ':saldo' => $surabayae));
        //echo  done  
        //array ends here for checkup

但是不幸的是,在沒有任何數據到數據庫表的情況下,它總是返回TRUE 僅更新,這應該在插入數據庫后完成。

我已經嘗試過對組合進行的所有組合更改,但我仍然茫然不知所措。 也不會返回任何錯誤。

只需按如下所示在Execute語句中刪除冒號(:),

以下代碼為我工作(添加了測試值)。

$statement = $link->prepare("INSERT INTO tb_beli(username, bank, norek, nama, ec, bitcoin, perfectmoney, fasapay, paket, saldo, amountbtc, phone, email, status, referer, iddb, date, ip, exp, unik,idph, upline, token)
VALUES(:username, :bank, :norek, :nama, :ec,  :bitcoin, :perfectmoney, :fasapay, :paket, :saldo, :amountbtc, :phone, :email, :status, :referer, :iddb, :date, :ip, :exp, :unik, :idph, :upline, :token)");

$kuriree = 'bb';
$bankee  = 'cc'; 
$norekee  = 'cc'; 
$namaee  = 'cc'; 
$matauang  = 'cc';  
$bitcoinee  = 'cc';
$pmee  = 'cc';
$fasapayee  = 'cc';
$paketzee  = 'cc'; 
$surabayae  = 'cc'; 
$convertbtc2  = 'cc';
$phoneee  = 'cc';
$emailee  = 'cc'; 
$status1  = 'cc';
$kurirz  = 'cc';
$idnyaz  = 'cc';
$skrg  = 'cc';
$laip   = 'cc';
$exp  = 'cc';
$unikee  = 'cc';
$idnyaee  = 'cc';
$mangkosim  = 'cc';
$unikeef   = 'aa';

$ret = $statement->execute(array('username' => $kuriree, 'bank' => $bankee, 'norek' => $norekee, 'nama' => $namaee, 'ec' => $matauang,  'bitcoin' => $bitcoinee, 'perfectmoney' => $pmee, 'fasapay' => $fasapayee, 'paket' => $paketzee, 'saldo' => $surabayae, 'amountbtc' => $convertbtc2, 'phone' => $phoneee, 'email' => $emailee, 'status' => $status1,'referer' => $kurirz,'iddb' => $idnyaz,'date' => $skrg,'ip' =>$laip ,'exp' => $exp,'unik' => $unikee,'idph' => $idnyaee,'upline' => $mangkosim,'token' => $unikeef ));

if($ret)
    print '1 row Inserted';
else
    print 'Error in Inserting';

似乎您每次都覆蓋$stmt變量,因此只有一個$stmt將起作用,最后一個$stmt update可能起作用。

嘗試這可能是您想要的:

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

try {

    $pdo->beginTransaction();

    //fetching error
    if ($stmt = $pdo->prepare("INSERT INTO tb_beli (username, bank, norek, nama, ec, bitcoin, perfectmoney, fasapay, paket, saldo, amountbtc, phone, email, status, referer, iddb, date, ip, exp, unik,idph, upline, token) 
        VALUES(:username, :bank, :norek, :nama, :ec,  :bitcoin, :perfectmoney, :fasapay, :paket, :saldo, :amountbtc, :phone, :email, :status, :referer, :iddb, :date, :ip, :exp, :unik, :idph, :upline, :token)")) {

        if (!$stmt->execute(array(
            ':username' => $kuriree,
            ':bank' => $bankee,
            ':norek' => $norekee,
            ':nama' => $namaee,
            ':ec' => $matauang,
            ':bitcoin' => $bitcoinee,
            ':perfectmoney' => $pmee,
            ':fasapay' => $fasapayee,
            ':paket' => $paketzee,
            ':saldo' => $surabayae,
            ':amountbtc' => $convertbtc2,
            ':phone' => $phoneee,
            ':email' => $emailee,
            ':status' => $status1,
            ':referer' => $kurirz,
            ':iddb' => $idnyaz,
            ':date' => $skrg,
            ':ip' => $laip,
            ':exp' => $exp,
            ':unik' => $unikee,
            ':idph' => $idnyaee,
            ':upline' => $mangkosim,
            ':token' => $unikeef
        ))) {


            $error = $stmt->errorInfo();
            throw new Exception($error);
        }

        if ($stmt_two = $pdo->prepare("INSERT INTO tb_jual (username, bank, norek, nama, ec,  bitcoin, perfectmoney, fasapay, paket, saldo, amountbtc, phone, email, status, date, ip, idgh, token) 
        VALUES(:username, :bank, :norek, :nama, :ec,  :bitcoin, :perfectmoney, :fasapay, :paket, :saldo, :amountbtc, :phone, :email, :status, :date, :ip, :idgh, :token)")) {

            if (!$stmt_two->execute(array(
                ':username' => $kurirz,
                ':bank' => $bankeem,
                ':norek' => $norekeem,
                ':nama' => $namaeem,
                ':ec' => $matauang,
                ':bitcoin' => $bitcoineem,
                ':perfectmoney' => $pmeem,
                ':fasapay' => $fasapayeem,
                ':paket' => $paketzee,
                ':saldo' => $surabayae,
                ':amountbtc' => $convertbtc2,
                ':phone' => $phoneeem,
                ':email' => $emaileem,
                ':status' => $status2,
                ':date' => $skrg,
                ':ip' => $laip,
                ':idgh' => $idnyaz,
                ':token' => $unikeef
            ))) {


                throw new Exception($stmt_two->errorInfo());
            }
        }

        if ($stmt_three = $pdo->prepare("UPDATE tb_ph SET saldo= (saldo - :saldo) where id=:id ")) {

            if (!$stmt_three->execute(array(
                ':id' => $idnyaee,
                ':saldo' => $surabayae
            ))) {

                throw new Exception($stmt_three->errorInfo());
            }
        }

        if ($stmt_four->$pdo->prepare("UPDATE tb_gh SET saldo= (saldo - :saldo) where id=:id")) {

            if (!$stmt_four->execute(array(
                ':id' => $idnyaz,
                ':saldo' => $surabayae
            ))) {

                throw new Exception($stmt_four->errorInfo());
            }
        }

    }

    if ($pdo->commit()) {
        echo "Data Proccessing complete";
    } else {
        throw new Exception('Transaction commit failed.');
    }
}
catch (Exception $e) {
    try {
        // something went wrong, we have to rollback
        $pdo->rollback();
        // and display the error message
        echo "error : " . $e->getMessage();
    }
    catch (Exception $f) {
        // and display the error message
        echo "error" . $f->getMessage();
    }
}

?> 

暫無
暫無

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

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