INSERT INTO LEFT JOIN php错误

时间:2013-12-29 04:00:40

标签: php mysql insert-into

我尝试修改代码时遇到了一些错误,如下所示。我希望创建一个INSERT INTO LEFT JOIN代码。

CODE

public function createPayments($item) {

        $stmt = mysqli_prepare($this->connection,  "INSERT INTO payments (payments.payment_id, payments.payment_amount,
                                                    payments.payment_date) SELECT students.student_id, students.firstname, students.lastname,
                                                    fee.fee_id, fee.fee_description, fee.class_id, fee.fee_amount, class.class_description
                                                    FROM students
                                                    LEFT JOIN class ON students.class_id = class.class_id
                                                    LEFT JOIN fee ON fee.class_id = class.class_id
                                                    LEFT JOIN payments ON payments.student_id = students.student_id
                                                    AND payments.fee_id = fee.fee_id");

        $this->throwExceptionOnError();
//line 81
        mysqli_stmt_bind_param($stmt, 'issi', $item->student_id, $item->fee_id, $item-> fee_description, $item->class_id, $item->fee_amount,
                                $item->firstname, $item->lastname,$item->class_description, 
                                $item->payment_amount, $item->payment_id, $item->payment_date->toString('YYYY-MM-dd HH:mm:ss') );
        $this->throwExceptionOnError();

        mysqli_stmt_execute($stmt);     
        $this->throwExceptionOnError();

        $autoid = mysqli_stmt_insert_id($stmt);

        mysqli_stmt_free_result($stmt);     
        mysqli_close($this->connection);

        return $autoid;
    }

    public function updatePayments($item) {

        $stmt = mysqli_prepare($this->connection, "UPDATE $this->query3 SET student_id=?, fee_id=?, fee_description=?, class_id=?, fee_amount=?,
                                                    firstname=?, lastname=?, payment_date=?, class_description=?, payment_amount=?,
                                                    payment_date=? where payment_id=?");        
        $this->throwExceptionOnError();

        mysqli_stmt_bind_param($stmt, 'issii',  $item->student_id, $item->fee_id, $item-> fee_description, $item->class_id, $item->fee_amount,
                                $item->firstname, $item->lastname, $item->payment_id, $item->payment_date->toString('YYYY-MM-dd HH:mm:ss'), 
                                $item->class_description, $item->payment_amount, $item->payment_date);
        $this->throwExceptionOnError();

        mysqli_stmt_execute($stmt);     
        $this->throwExceptionOnError();

        mysqli_stmt_free_result($stmt);     
        mysqli_close($this->connection);
    }


    public function deletePayments($itemID) {

        $stmt = mysqli_prepare($this->connection, "DELETE FROM $this->query3 WHERE payment_id = ?");
        $this->throwExceptionOnError();

        mysqli_stmt_bind_param($stmt, 'i', $itemID);
        mysqli_stmt_execute($stmt);
        $this->throwExceptionOnError();

        mysqli_stmt_free_result($stmt);     
        mysqli_close($this->connection);
    } 

错误 mysqli_stmt_bind_param可能出现问题......

There was an error while invoking the operation. Check your operation inputs or server code and try invoking the operation again. 

Reason: 
Warning: Attempt to modify property of non-object in C:\wamp\www\feez3\services\PaymentsService3.php on line 81

    Warning: Attempt to modify property of non-object in C:\wamp\www\feez3\services\PaymentsService3.php on line 81

    Warning: Attempt to modify property of non-object in C:\wamp\www\feez3\services\PaymentsService3.php on line 81

    Warning: Attempt to modify property of non-object in C:\wamp\www\feez3\services\PaymentsService3.php on line 81

    Warning: Attempt to modify property of non-object in C:\wamp\www\feez3\services\PaymentsService3.php on line 81

    Warning: Attempt to modify property of non-object in C:\wamp\www\feez3\services\PaymentsService3.php on line 81

    Warning: Attempt to modify property of non-object in C:\wamp\www\feez3\services\PaymentsService3.php on line 82

    Warning: Attempt to modify property of non-object in C:\wamp\www\feez3\services\PaymentsService3.php on line 82

    Warning: Attempt to modify property of non-object in C:\wamp\www\feez3\services\PaymentsService3.php on line 82

    Warning: Attempt to modify property of non-object in C:\wamp\www\feez3\services\PaymentsService3.php on line 83

    Warning: Attempt to modify property of non-object in C:\wamp\www\feez3\services\PaymentsService3.php on line 83

    Fatal error: Call to a member function toString() on a non-object in C:\wamp\www\feez3\services\PaymentsService3.php on line 83

这里有人经历过同样的情况吗?请通过这个指导我。谢谢。

1 个答案:

答案 0 :(得分:1)

就在这里

payments.payment_id,, 

你有两个逗号,删除一个。