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 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿