當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Book::createBook方法代碼示例

本文整理匯總了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>";
開發者ID:nicolasrafaelli,項目名稱:php-bootcamp,代碼行數:24,代碼來源:correct.php

示例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);
開發者ID:BartoszJanGodlewski,項目名稱:LibraryWorkshop,代碼行數:20,代碼來源:books.php

示例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
開發者ID:BartoszJanGodlewski,項目名稱:UnusedLibraryWorkshop,代碼行數:31,代碼來源:api.php


注:本文中的Book::createBook方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。