PHP runs normally under the Linux terminal but does not solve the headache properly
Source: Internet
Author: User
PHP is running on a computer normally on a Linux terminal, but it doesn't solve the headache properly.
Contents of my PHP File:
Always hint fatal error; Call to a member function query () on a non-object online 16
$DB->connection->query ("CREATE TABLE test", ID integer primary key,name varchar (grade varchar), score varchar (50)); Keep suggesting this is a mistake. I'm stuck here.
I run on the computer is completely normal can insert data is running on the Linux terminal has always been prompt error is crazy is the terminal setup problem?
Get the data submitted by the Uiceshi.html page.
$fname = $_post[' fname '); Name
$fgrade = $_post[' Fgrade '); Grade
$fscore = $_post[' Fscore '); Scores
$sql = ' INSERT into test values (); ';
Create a DB instance
$DB = new SQLite (' blog.db '); This database file name is arbitrary
To create a table with table name test
$DB->connection->query ("CREATE TABLE test", ID integer primary key,name varchar (grade varchar), score varchar (50)) "); Prompt for an error in this line
Execute INSERT statement
$result = $DB->query ("INSERT into Test (Name,grade,score) VALUES ('". $fname. "', '". $fgrade. "', '". $fscore. "')");
$result = $DB->connection->query ("INSERT into Test (Name,grade,score) VALUES ('". $fname. "', '". $fgrade. "', '". $ Fscore. "')");
The return result is primarily for debugging
Print_r ($result);
function __destruct ()
{
$this->connection=null;
}
function query ($sql)//Run SQL directly to update, delete data
{
return $this->connection->query ($sql);
}
function GetList ($sql)//Get a list of records
{
$recordlist =array ();
foreach ($this->query ($sql) as $rstmp)
{
$recordlist []= $rstmp;
}
return $recordlist;
}
function Execute ($sql)
{
return $this->query ($sql)->fetch ();
}
function Recordarray ($sql)
{
return $this->query ($sql)->fetchall ();
}
function RecordCount ($sql)
{
Return count ($this->recordarray ($sql));
}
function Recordlastid ()
{
return $this->connection->lastinsertid ();
}
}
?>
------Solution--------------------
SQLite under Linux is not installed.
------Solution--------------------
Are there writable permissions to the directory where SQLITE data files are stored?
discuss
But you can read it. If you put a data data.db on Linux, you can read it on the terminal, but you can't insert the data.
------Solution--------------------
Give 7777 permissions
------Solution--------------------
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.