Alzecha
Alzecha

Reputation: 77

PHP data query error with object/string, now SQLite3 construct

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?

Upvotes: 0

Views: 754

Answers (2)

ADH - THE TECHIE GUY
ADH - THE TECHIE GUY

Reputation: 4373

I'm posting this answer on 31-1-2019 ,for people they just come here by following the thumbnail I also faced same problem and finally I found the solution the problem is with your construct() method , you missed one '_'

there we have two construct method()

1.__construct() ,with two '_' ,which requires no parameters

2._construct() ,with one '_', which requires some parameters

Upvotes: 0

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

Upvotes: 1

Related Questions