Php runs normally on the computer on the linux Terminal but it does not solve the headache among my php file content: always prompt fatalerror; calltoamemberfunctionquery () onanon-objectonline16 $ DB-& gt; connection-& gt; query (& quot; createtabletest (idi php runs normally on the computer on the linux terminal, but it does not solve the problem.
My php file content:
Always prompts 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 (50), grade varchar (50), score varchar (50 ))"); this line of error always prompts me to paste it here
It is completely normal for me to run on the computer. I can insert data. when I run the data on a linux Terminal, I keep prompting that the error is going crazy. Is it a problem with terminal settings?
Header ("content-Type: text/html; charset = Utf-8 ");
// Obtain the data submitted on the uiceshi.html page
$ Fname = $ _ POST ['fname']; // name
$ Fgrade = $ _ POST ['fgrade ']; // grade
$ Fscore = $ _ POST ['fscore']; // score
// $ SQL = 'Insert into test values ();';
// Create a database instance
$ DB = new SQLite ('Blog. db'); // the database file name is arbitrary.
// Create a table named test
$ DB-> connection-> query ("create table test (id integer primary key, name varchar (50), grade varchar (50), score varchar (50 ))"); this line of error is prompted
// Execute the 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 returned results are mainly used for debugging.
Print_r ($ result );
// SQLite class
Class SQLite
{
Function _ construct ($ file)
{
Try
{
$ This-> connection = new PDO ('sqlite: '. $ file );
}
Catch (PDOException $ e)
{
Try
{
$ This-> connection = new PDO ('sqlite2: '. $ file );
}
Catch (PDOException $ e)
{
Exit ('error! ');
}
}
}
Function _ destruct ()
{
$ This-> connection = null;
}
Function query ($ SQL) // Runs SQL directly, which can be used to update or delete data.
{
Return $ this-> connection-> query ($ SQL );
}
Function getlist ($ SQL) // retrieves the record list
{
$ 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 in LINUX is not installed.
------ Solution --------------------
Does the directory where SQLITE data files are stored have the write permission?
Discussion
But it can be read out. if you put data. db in the linux underground, the terminal can read but cannot insert data.
------ Solution --------------------
Grant 7777 permissions
------ Solution --------------------