我的php文件内容:一直提示 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))");一直提示这行出错我贴在这里
我在电脑上运行是完全正常的 可以插入数据 是在linux终端机上运行时就一直提示错误 要疯了 是终端机设置的问题吗
<?phpheader("content-Type: text/html; charset=Utf-8"); //获取uiceshi.html页面提交过来的数据
$fname = $_POST['fname']; //姓名
$fgrade = $_POST['fgrade']; //年级
$fscore = $_POST['fscore']; //分数//$sql = 'insert into test values ();'; //创建一个数据库实例$DB = new SQLite('blog.db'); //这个数据库文件名字任意 //创建表名为test的表
$DB->connection->query("create table test(id integer primary key,name varchar(50),grade varchar(50),score varchar(50))"); 提示这行出错//执行插入语句
//$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."')");//返回结果 主要是用来调试的
print_r($result);
//SQLite类
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) //直接运行SQL,可用于更新、删除数据
{
return $this->connection->query($sql);
}
function getlist($sql) //取得记录列表
{
$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();
}
}
?>
我在电脑上运行是完全正常的 可以插入数据 是在linux终端机上运行时就一直提示错误 要疯了 是终端机设置的问题吗
<?phpheader("content-Type: text/html; charset=Utf-8"); //获取uiceshi.html页面提交过来的数据
$fname = $_POST['fname']; //姓名
$fgrade = $_POST['fgrade']; //年级
$fscore = $_POST['fscore']; //分数//$sql = 'insert into test values ();'; //创建一个数据库实例$DB = new SQLite('blog.db'); //这个数据库文件名字任意 //创建表名为test的表
$DB->connection->query("create table test(id integer primary key,name varchar(50),grade varchar(50),score varchar(50))"); 提示这行出错//执行插入语句
//$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."')");//返回结果 主要是用来调试的
print_r($result);
//SQLite类
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) //直接运行SQL,可用于更新、删除数据
{
return $this->connection->query($sql);
}
function getlist($sql) //取得记录列表
{
$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();
}
}
?>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货