一旦我运行select query($ result),php页面就会变为空白

时间:2014-11-28 16:55:01

标签: php mysql

所以我试图连接到数据库服务器并从sakila架构中获取信息。连接工作正常,查询也很可靠。但是当我运行php文件时,我得到一个空白页面。如果我删除行:

$result = mysql_query($select_query);
$table = array();
while($r = mysql_fetch_array($result) {
    $row = array();
    foreach($r as $k=>$v) {
         $row[$k] = $v;
    }
    array_push($table,$row);
    unset($row);

然后页面输出内容。但当它在那里时,页面变成空白。即使错误报告的内容也不可见。发生了什么事?

代码段:

<?php

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

  echo "balls";
  // Connecting to MySQL
  require '../app_config.php';

  mysql_connect($database_host, $username, $password)
  or die("<p>Error connecting to database: " . mysql_error() . "</p>");

  // Selecting the database
  mysql_select_db("sakila")
  or die("<p>Error selecting the database sakila: " . mysql_error() . "</p>");

  // Build the SELECT statement
  $select_query = "SELECT c.customer_id, concat(c.first_name,' ', c.last_name) as 'name', c.email, ad.phone, concat(ad.address, ad.address2,', ', ad.postal_code,', ', ci.city,', ', co.country) as address FROM customer as c, address as ad, city as ci, country as co WHERE ad.address_id = c.address_id and ad.city_id = ci.city_id and ci.country_id = co.country_id limit 10";
  echo "balls deep";
  // Run the query
  $result = mysql_query($select_query);
  $table = array();
  while($r = mysql_fetch_array($result) {
    $row = array();
    foreach($r as $k=>$v) {
         $row[$k] = $v;
    }
    array_push($table,$row);
    unset($row);
  }

?>

<html>
  <head>
    <title>Customer Details</title>
  </head>
  <body>
 Hello
  </body>
</html>

0 个答案:

没有答案