PHP - SQL更新和替换问题

时间:2016-01-19 02:01:13

标签: php mysql sql

我的表的示例称为“帐户”:

game          accounts
---------------------------------
minecraft_pc  test:123
cod           123:test
bla           blabla

当他们使用PayPal IPN购买帐户时,此查询将在脚本中发送:

query("UPDATE accounts SET accounts = REPLACE(accounts, :boughtaccount, '') WHERE game = :game","unfed_shop",array(":game"=>$_POST['item_name'],":boughtaccount"=>$accountquery));

出于某种原因它无法工作我知道这个问题不是自定义查询()。

完整的PHP:

//Prepare the Statements for the query;
if(strpos($st[0]['accounts'],',')) {
    $accountquery = $st2[0].', ';
} else {
    $accountquery = $st2[0];
}

//Remove the ready account from the database;
query("UPDATE accounts SET accounts = REPLACE(accounts, :boughtaccount, '') WHERE game = :game","unfed_shop",array(":game"=>$_POST['item_name'],":boughtaccount"=>$accountquery));

query()PHP:

function Connect($host = false,$username = false,$password = false,$dbname = false) {

    //Try execute the PHP with no errors;
    try {

        //Create a PDO Session;
        $con = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);

        //Session Attributes;
        $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $con->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);

    }

    //Catch all PDOException errors;
    catch (PDOException $e) {

        //Make the PDO session false;
        $con = false;

    }

    //If no errors happened Make the PDO session true;
    return $con;

}

function query($sql = false,$dbname = false,$bind = false,$obj = false) {

    //Prepare The SQL Query;
    $query = Connect('localhost','unfed_admin','pass',$dbname)->prepare($sql);

    $res = true;

    //Execute Binded Query;
    try { $query->execute($bind); $res = true; }

    catch (PDOException $e) {

        $res = false;

    }

    //If no errors happened Make $row true;
    return $res;

}

由于某些原因,我没有得到任何错误。有什么想法吗?

0 个答案:

没有答案