欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

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

程序员文章站 2022-04-21 20:31:49
...
mysqlphp

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

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

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

     
TODO supply a title


Book-O-Rama Book Entry Result

". "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(); ?>
相关标签: mysql php