PHP中发生什么意外的'$ pdo'(T_VARIABLE)错误?

时间:2019-01-23 04:59:01

标签: php database gridview datagridview

这是一个小的php代码,用于从this建立数据库gridview引用,它对我的​​代码有错误。我不知道要解决此错误,请帮助我找到它。

错误:解析错误:语法错误,意外的“ $ pdo”(T_VARIABLE)

<?php include ('database.php');                                              
      $pdo = Database::connect();                                           
      $sql = 'SELECT * FROM student list';                               
      foreach ($pdo->query($sql) as $row) {                                 
           echo '<tr>';                                                     
           echo '<td>'. $row['Name'] . '</td>';                             
           echo '<td>'. $row['Surname'] . '</td>';                          
           echo '<td>'. $row['Nickname'] . '</td>';                         
           echo '<td>'. $row['Education Program'] . '</td>';                
           echo '<td>'. $row['Note'] . '</td>';                          
           echo '<td>'. $row['GPAX'] . '</td>';                          
           echo '</tr>';                                                    
           }                            
      Database::disconnect();                                               
?>

这是我在database.php中包含的代码。

<?php class Database {
private static $dbName = 'newtest' ;
private static $dbHost = 'localhost' ;
private static $dbUsername = 'root';
private static $dbUserPassword = '1234';

private static $cont  = null;

public function __construct() {
    die('Init function is not allowed');
}

public static function connect()
{
   // One connection through whole application
   if ( null == self::$cont )
   {     
    try
    {
      self::$cont =  new PDO( "mysql:host=".self::$dbHost.";"."dbname=".self::$dbName, self::$dbUsername, self::$dbUserPassword); 
    }
    catch(PDOException $e)
    {
      die($e->getMessage()); 
    }
   }
   return self::$cont;
}

public static function disconnect()
{
    self::$cont = null;
}}?>                                                                

0 个答案:

没有答案