douli8040
2014-04-16 02:33
浏览 26
已采纳

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

I am using MYSQLi (from this website: http://codular.com/php-mysqli) and getting a blank page.

<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>

图片转代码服务由CSDN问答提供 功能建议

我正在使用MYSQLi(来自这个网站: http://codular.com/php-mysqli )并获得一个空白页面。

 &lt; html&gt; 
&lt;  ;主体&GT;  
&lt; h1&gt; TEST21&lt; / h1&gt; 
 
&lt;?php 
 
 error_reporting(E_ALL);  ini_set('display_errors',1); 
 
 $ db = new mysqli('localhost','Brendan','password','Library'); 
 
 if($ db-&gt; connect_errno&gt;  0){
 die('无法连接到数据库['。$ db-&gt; connect_error。']'); 
} 
 
回显“STEP1”; 
 
 //步骤2 
  
 $ sql =&lt;&lt;&lt; SQL 
 SELECT * 
 FROM'BOOK'
 WHERE'ISBN10'&gt;  0 
 SQL; 
 
 if if(!$ result = $ db-&gt; query($ sql)){
 die('运行查询时出错['。$ db-&gt;错误。'  ]'); 
} 
 
回显“STEP2”; 
 
?&gt; 
 
&lt; / body&gt; 
   
 
 

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douzangdang2225 2014-04-16 03:07
    已采纳

    The whacky thing with HEREDOC is that the closing identifier must not have any leading spaces (must not be indented). See the big warning here - http://php.net/manual/language.types.string.php#language.types.string.syntax.heredoc

    You're also using the wrong quote characters in your query. I'd simplify it all down to this...

    $sql = 'SELECT * FROM `BOOK` WHERE `ISBN10` > 0';
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题