INSERT INTO无所作为

时间:2019-12-12 18:23:36

标签: php mysql oop

一个简单的问题。以下代码未在MySQL数据库中创建数据,但完全相同的Query在PHPmyadmin中运行。怎么了?

        $db = new Database();
        $dbr = $db->query('SELECT * FROM `cards` WHERE `id` = '.$this->id);

        if(isset($dbr[0]))
        {
            $db->nquery('UPDATE `cards` SET `id`='.$this->id.', `timestamp`='.$this->timestamp.', `creatorname`='.$this->staffName.', `creatorid`='.$this->staffNumber.', `panr`='.$this->orderNumber.', `cnr`='.$this->lotNumber.', `anr`='.$this->itemNumber.', `errorid`='.$this->errorid.', `open`='.$this->open.' WHERE id=`'.$this->id.'`');
            $result = true;
        }
        else
        {
            $queryFormat = 'INSERT INTO `cards` (`id`, `timestamp`, `creatorname`, `creatorid`, `panr`, `cnr`, `anr`, `errorid`, `open`) VALUES (`%d`, `%d`, `%s`, `%s`, `%s`, `%s`, `%s`, `%d`, `%d`)';

            $this->id = $db->generateID('cards');
            $db->nquery(sprintf($queryFormat, $this->id, $this->timestamp, $this->staffName, $this->staffNumber, $this->orderNumber, $this->lotNumber, $this->itemNumber, $this->errorid, $this->open));

数据库对象与SELECT之类的查询配合良好。但是不能用INSERT INTO 这是数据库功能:

 public function nquery(string $param): void
    { 
        $this->sql->query($param);
    }

感谢帮助!

0 个答案:

没有答案