>  기사  >  백엔드 개발  >  mysql-PHP,MySQL请问这两行代码有什么区别?

mysql-PHP,MySQL请问这两行代码有什么区别?

WBOY
WBOY원래의
2016-06-02 11:33:441111검색

mysqlphp

请问这两行代码有什么区别?我试了一下都可以运行成功。

<code> $query = "insert into books values (' ".$isbn." ', ' ".$author." ', ' ".$title." ', ' ".$price." ')";</code>
<code>$query = "insert into books values (' $isbn ', ' $author ', ' $title', ' $price ')";` </code>

完整代码from PHP和MySQL Web开发(原书第4版):

<code>             <title>TODO supply a title</title>        <meta charset="UTF-8">        <meta name="viewport" content="width=device-width, initial-scale=1.0">                <h1>Book-O-Rama Book Entry Result</h1>        <?php //create short variable names        $isbn=$_POST['isbn'];        $author=$_POST['author'];        $title=$_POST['title'];        $price=$_POST['price'];        if (!$isbn || !$author || !$title || !$price){            echo "You have not entered all the required details. <br />". "Please go back and try again";            exit;        }        if (!get_magic_quotes_gpc()){            $isbn = addslashes($isbn);            $author = addslashes($author);            $title = addslashes($title);            $price = doubleval($price);        }        @ $db = new mysqli('localhost', 'root', '123', 'mydb');        if (mysqli_connect_errno()){            echo "Error: Could not connect to database. Please try again later.";            exit;        }        $query = "insert into books values (' ".$isbn." ', ' ".$author." ', ' ".$title." ', ' ".$price." ')";        $result = $db->query($query);        if ($result) {            echo $db->affected_rows. "book inserted into database.";        }  else {                echo "An error has occurred. The item was not added.";        }        $db->close();        ?>    </code>
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.