如何使用MYSQLi和PHP显示信息?

时间:2014-04-16 02:33:25

标签: php mysql mysqli

我正在使用MYSQLi(来自此网站:http://codular.com/php-mysqli)并获取空白页。

<html>
<body>  
    <h1>TEST21</h1>

    <?php

    error_reporting(E_ALL);  ini_set('display_errors', 1);

    $db = new mysqli('localhost', 'Brendan', 'password', 'Library');

    if($db->connect_errno > 0){
        die('Unable to connect to database [' . $db->connect_error . ']');
    }

    echo "STEP1";

    //STEP 2

    $sql = <<<SQL
        SELECT *
        FROM 'BOOK'
        WHERE 'ISBN10' > 0
    SQL;

    if(!$result = $db->query($sql)){
        die('There was an error running the query [' . $db->error . ']');
    }

    echo "STEP2";

    ?>

</body>

1 个答案:

答案 0 :(得分:4)

HEREDOC令人讨厌的事情是,结束标识符不能有任何前导空格(不得缩进)。请参阅此处的重大警告 - http://php.net/manual/language.types.string.php#language.types.string.syntax.heredoc

您还在查询中使用了错误的引号字符。我简化了这一切......

$sql = 'SELECT * FROM `BOOK` WHERE `ISBN10` > 0';