donqo88682 2014-12-09 03:36
浏览 75
已采纳

PHP数据查询错误与对象/字符串,现在SQLite3构造

I have a website.

I recently had to extend Sqlite3 to use some functions and define some custom ones, but I now have this error message:

Fatal error: Uncaught exception 'Exception' with message 'SQLite3::__construct() expects at least 1 parameter, 0 given' line 138

this is the line 138:

$output = new functions(); $output-> bothQuery();

My class extending sqlite3:

class functions extends SQLite3 {
  // Functions to sort data based on input
  public function bothQuery() { /*...*/ }
  function nameQuery() { /*...*/ }
  function cateQuery() { /*...*/ }
}

How can I solve this?

  • 写回答

2条回答 默认 最新

  • duanpa5237 2014-12-09 03:58
    关注

    Alzecha commented:

    Also, line 138 is in the upper code segment, where it says $output = new functions();

    you should learn from basic php oop tutorials but here is the problem you're facing:

    the Sqlite3 class seems to have a constructor. Classes generally have constructors. A constructor sometimes takes parameters, such as the constructor for the Sqlite3 class

    what happens when you extend a class class functions extends SQLite3 is that it will use it's parent (that is, Sqlite3) constructor if it is not defined in the child (that is, functions) class. Sqlite3 constructor, as we can see from it's manual page, wants a parameter, (a filename of a sqlite database) as it's first parameter. so when you do:

    $output = new functions();
    

    you're actually constructing an Sqlite3 instance, even though it's called functions, because functions extends SQLite3. So you have to give it a normal parameter, the same you would give when calling new Sqlite3()

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效