再次陷入对象/类。我有一个名为 submitticket 的函数,它将向我的票证表中提交一个新行。
public function submitticket() {
$correct = false;
try {
$con = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
$con->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sql = "INSERT INTO tickets (ticketid, EPMSAccount, requester, recipient, jobnumber, subject, body, responseid, type, priority) VALUES (:ticketid, :EPMSAccount, :requester, :recipient, :jobnumber, :subject, :body, :responseid, :type, :priority)";
$stmt = $con->prepare( $sql );
//print_r($sql);
$stmt->bindValue( "ticketid", $this->ticketid, PDO::PARAM_STR );
$stmt->bindValue( "EPMSAccount", $this->EPMSAccount, PDO::PARAM_STR );
$stmt->bindValue( "requester", $this->requester, PDO::PARAM_STR );
$stmt->bindValue( "recipient", $this->recipient, PDO::PARAM_STR );
$stmt->bindValue( "jobnumber", $this->jobnumber, PDO::PARAM_STR );
$stmt->bindValue( "subject", $this->subject, PDO::PARAM_STR );
$stmt->bindValue( "body", $this->body, PDO::PARAM_STR );
$stmt->bindValue( "responseid", $this->responseid, PDO::PARAM_STR );
$stmt->bindValue( "type", $this->type, PDO::PARAM_STR );
$stmt->bindValue( "priority", $this->priority, PDO::PARAM_STR );
echo '<pre>';
print_r($stmt);
echo '</pre>';
$stmt->execute();
return "Ticket created!";
}catch( PDOException $e ) {
return $e->getMessage();
}
这就是我在代码中执行它的方式:
// Submit ticket if submit clicked
if($_POST['submit'] == 'Submit Ticket'){
$_POST['requester'] = $_SESSION['name'];
$_POST['EPMSAccount'] = $_SESSION['EPMSAccount'];
$tkt = new Ticket; // New instance of ticket class
$tkt->storeFormValues( $_POST );
$tkt->storeFormValues( $_SESSION );
$tkt->submitticket();
echo '<pre>';
var_dump($tkt);
print_r ($stmt);
echo '</pre>';
} else {
echo 'nothing attempted';
}
我知道这个查询应该是正确的,但它没有向我的表写入任何内容。这是 var_dump 和 print_r 给我的:
PDOStatement Object
(
[queryString] => INSERT INTO tickets (ticketid, EPMSAccount, requester, recipient, jobnumber, subject, body, responseid, type, priority) VALUES (:ticketid, :EPMSAccount, :requester, :recipient, :jobnumber, :subject, :body, :responseid, :type, :priority)
)
object(Ticket)#2 (12) {
["ticketid"]=>
NULL
["EPMSAccount"]=>
string(7) "SHAWMUT"
["jobnumber"]=>
string(6) "123456"
["estnumber"]=>
NULL
["requester"]=>
string(14) "Gabriel Peluso"
["recipient"]=>
string(16) "Customer Service"
["subject"]=>
string(4) "2323"
["body"]=>
string(5) "23232"
["order"]=>
NULL
["responseid"]=>
NULL
["type"]=>
NULL
["priority"]=>
string(6) "Normal"
}
我不知道如何使用绑定的 PDO 值查看实际的 SQL 查询。有可能生产吗?有什么办法可以找出为什么它不写到桌子上?