本文整理汇总了PHP中Respond::success方法的典型用法代码示例。如果您正苦于以下问题:PHP Respond::success方法的具体用法?PHP Respond::success怎么用?PHP Respond::success使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Respond
的用法示例。
在下文中一共展示了Respond::success方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: mysqli
<?php
require_once 'config.php';
require_once 'inc/respond.php';
$db = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
// connect to the DB
$respond = new Respond();
// Send out JSON responses
$table = 'fv_data';
if ($db->connect_errno) {
$respond->fail("Failed to connect to MySQL: " . $db->connect_error);
}
// All setup - let's get started with handling any data.
$res = $db->query("SELECT *,DATE_FORMAT(dob,'%D %M %Y') as dob_formatted FROM {$table} ORDER BY id DESC");
while ($row = $res->fetch_assoc()) {
$data['results'][] = $row;
}
$respond->success("results", $data);
示例2:
}
}
// If we made it this far, the data is generally okay
// so let's prepare and submit.
$stmt = $db->prepare("INSERT INTO {$table} \n\t(firstname, lastname, email, phone, gender, dob, comments)\n\tVALUES (?,?,?,?,?,?,?)");
$stmt->bind_param('sssssss', $firstname, $lastname, $email, $phone, $gender, $dob, $comments);
$stmt->execute();
if ($stmt->error) {
$respond->fail('Database Error', $stmt);
} else {
/*
// This is just an example of how the form could send a thank you email, or an email to an administrator
// Without some sort of throttling and verification it could totally be used to spam people, it's just a proof of concept though!
// If it was real there should probably be some sort of "I am not a robot" captcha on the front end.
$mail->addAddress('cowfields@gmail.com', 'FV Form'); // Add a recipient
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Submission Received';
$mail->Body = 'New Submission received...here are the results etc etc';
if(!$mail->send()) {
// echo 'Message could not be sent.';
// echo 'Mailer Error: ' . $mail->ErrorInfo;
}
*/
// Send a Success message via JSON
$respond->success("updated", $stmt);
}
$stmt->close();