-1

这是 test.php

<?php

include("../includes/database.php");
$db = new Database();
$sql = "SELECT * FROM users WHERE username='mr.man' ";
$db->query($sql);
$db->singleRecord(); //call this if the query will only return a single row 
echo $db->Record['password']; // use the field name for example or; 
echo $db->Record[0]; //use indexes
echo "test";

这是database.php

class Database{
private $Host     ="localhost";    // Hostname of our MySQL server.
private $Database ="admin_db";  // Logical database name on that server.
private $User     ="user";             // User and Password for login.
private $Password ="xxx";
private $Link_ID  = 0;                  // Result of mysql_connect().
private $Query_ID = 0;                  // Result of most recent mysql_query().
private $Record = array();            // current mysql_fetch_array()-result.
private $Row;                           // current row number.
private $LoginError = "";
private $Errno    = 0;                  // error state of query...
private $Error    = "";
} // end class Database

我已经删除了类中的函数以找到我收到的 PHP 解析错误的根源。我检查了我是否以 ; 结尾的语句。并且也有匹配的“。我仍然不明白为什么我会收到:

解析错误:语法错误,意外的 T_STRING,在第 4 行的 /var/www/vhosts/example.com/httpdocs/includes/database.php 中需要 T_FUNCTION

4

1 回答 1

3

var(这不是Javascript)替换为private

class Database{
    private $Host     ="localhost";    // Hostname of our MySQL server.
    private $Database ="admin_db";  // Logical database name on that server.
    private $User     ="user";             // User and Password for login.
    private $Password ="xxx";
    private $Link_ID  = 0;                  // Result of mysql_connect().
    private $Query_ID = 0;                  // Result of most recent mysql_query().
    private $Record = array();            // current mysql_fetch_array()-result.
    private $Row;                           // current row number.
    private $LoginError = "";
    private $Errno    = 0;                  // error state of query...
    private $Error    = "";
} // end class Database
于 2012-08-27T03:13:37.150 回答