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条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里