本文整理汇总了PHP中Book::createBook方法的典型用法代码示例。如果您正苦于以下问题:PHP Book::createBook方法的具体用法?PHP Book::createBook怎么用?PHP Book::createBook使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Book
的用法示例。
在下文中一共展示了Book::createBook方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createBook
<?php
class Book
{
public function createBook()
{
$ntitle = mysql_real_escape_string($_GET['ntitle']);
$nprice = filter_var($_GET['nprice'], FILTER_VALIDATE_FLOAT);
$ndesc = mysql_real_escape_string($_GET['ndesc']);
$link = mysql_connect('localhost', 'root', '') or die('No se pudo conectar al servidor: ' . mysql_error());
mysql_select_db('books') or die('No se pudo seleccionar la base de datos');
mysql_query("SET NAMES 'utf8'");
$query = "INSERT INTO `books`(`title`,`price`,`description`) VALUES ('{$ntitle}','{$nprice}','{$ndesc}')";
$result = mysql_query($query) or die('Consulta fallida: ' . mysql_error());
if ($result) {
echo "Insertado.";
}
mysql_close($link);
}
}
$book = new Book();
$book->createBook();
echo "<br><br>";
echo "<a href='index.php'>Back</a>";
示例2: json_encode
<?php
require_once "api.php";
$ret = [];
$method = $_SERVER['REQUEST_METHOD'];
$book = new Book();
switch ($method) {
case 'GET':
$bookId = $_GET['bookId'];
$ret['bookList'] = $book->loadFromDB($bookId);
break;
case 'POST':
$bookTitle = $_POST['bookTitle'];
$bookAuthor = $_POST['bookAuthor'];
$bookDescription = $_POST['bookDescription'];
$book->createBook($bookTitle, $bookAuthor, $bookDescription);
$ret['bookList'] = $book->loadFromDB();
break;
}
echo json_encode($ret);
示例3: Book
if ($db->connect_error) {
$error = $db->connect_error . '(' . $db->connect_errno . ')';
// sprawdzamy error w dżejsonie
// utworzylismy tablice dżejsonową o kluczu error i wartosci error
$json = json_encode(['error' => $error]);
echo $json;
} else {
//przetwarzamy odebrane dane ajaxem z formularza PUT/POST/DELETE/GET
$method = $_SERVER['REQUEST_METHOD'];
$book = new Book($db);
switch ($method) {
case 'GET':
$data = $_GET;
break;
case 'POST':
$data = $_POST;
$book->createBook($data);
//zwracamy do ajaxa wszystkie ksiazki, o ktore pytamy w clasie book.class.php
$ret['KbookList'] = $book->getBooks();
$ret['success'] = 'Ksiazka zostala dodana prawidlowo';
break;
// PUT i DELETE zapisuje się w ten sam sposob dlatego robimy to razem
// PUT i DELETE zapisuje się w ten sam sposob dlatego robimy to razem
case 'PUT':
case 'DELETE':
parse_str(file_get_contents('php://input'), $data);
break;
}
echo json_encode($ret);
}
//tworzymy obiekt klasy book i wykonujemy odpowiednie operacje