search
HomeBackend DevelopmentPHP Tutorialphp在电脑下运行正常在linux终端机下却不正常 求解 头疼当中

php在电脑上运行正常在linux终端机上却不正常 求解 头疼当中
我的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终端机上运行时就一直提示错误 要疯了 是终端机设置的问题吗



header("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下的SQLITE没有装好吧
------解决方案--------------------
SQLITE 数据文件存放的目录是否有可写权限呢?

探讨

但是能读出来啊 如果把有数据的 data.db 放在linux地下就是终端机上 可以读取但是不能插入数据

------解决方案--------------------
赋予 7777 权限
------解决方案--------------------
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP Performance Tuning for High Traffic WebsitesPHP Performance Tuning for High Traffic WebsitesMay 14, 2025 am 12:13 AM

ThesecrettokeepingaPHP-poweredwebsiterunningsmoothlyunderheavyloadinvolvesseveralkeystrategies:1)ImplementopcodecachingwithOPcachetoreducescriptexecutiontime,2)UsedatabasequerycachingwithRedistolessendatabaseload,3)LeverageCDNslikeCloudflareforservin

Dependency Injection in PHP: Code Examples for BeginnersDependency Injection in PHP: Code Examples for BeginnersMay 14, 2025 am 12:08 AM

You should care about DependencyInjection(DI) because it makes your code clearer and easier to maintain. 1) DI makes it more modular by decoupling classes, 2) improves the convenience of testing and code flexibility, 3) Use DI containers to manage complex dependencies, but pay attention to performance impact and circular dependencies, 4) The best practice is to rely on abstract interfaces to achieve loose coupling.

PHP Performance: is it possible to optimize the application?PHP Performance: is it possible to optimize the application?May 14, 2025 am 12:04 AM

Yes,optimizingaPHPapplicationispossibleandessential.1)ImplementcachingusingAPCutoreducedatabaseload.2)Optimizedatabaseswithindexing,efficientqueries,andconnectionpooling.3)Enhancecodewithbuilt-infunctions,avoidingglobalvariables,andusingopcodecaching

PHP Performance Optimization: The Ultimate GuidePHP Performance Optimization: The Ultimate GuideMay 14, 2025 am 12:02 AM

ThekeystrategiestosignificantlyboostPHPapplicationperformanceare:1)UseopcodecachinglikeOPcachetoreduceexecutiontime,2)Optimizedatabaseinteractionswithpreparedstatementsandproperindexing,3)ConfigurewebserverslikeNginxwithPHP-FPMforbetterperformance,4)

PHP Dependency Injection Container: A Quick StartPHP Dependency Injection Container: A Quick StartMay 13, 2025 am 12:11 AM

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Dependency Injection vs. Service Locator in PHPDependency Injection vs. Service Locator in PHPMay 13, 2025 am 12:10 AM

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHP performance optimization strategies.PHP performance optimization strategies.May 13, 2025 am 12:06 AM

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHP Email Validation: Ensuring Emails Are Sent CorrectlyPHP Email Validation: Ensuring Emails Are Sent CorrectlyMay 13, 2025 am 12:06 AM

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools