这是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
答案 0 :(得分:3)
用var
替换private
(这不是Javascript):
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