0

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?

4
  • SQLite3::__construct() expects at least 1 parameter, 0 given I'd say find the place where the sqlite object is created and give it the parameter it very clearly states it wants? it's probably that the class extending sqlite does not construct it in the right way. it may be there: new class(). you can see there are no parameters passed in the parenthesis, as opposed to expects at least 1 parameter. Also, where is line 138? Commented Dec 9, 2014 at 3:40
  • Thank you for the response. I know it seems pretty obvious, but to be quite honest I don't know exactly what it wants as the parameter. I've never been taught to call a specific php function that's in a class like that, I don't know if it's asking for a paremeter from the class or the function I want to call. Also, line 138 is in the upper code segment, where it says $output = new functions(); $output-> bothQuery(); Commented Dec 9, 2014 at 3:45
  • I would consult the manual page for the sqlite3 class constructor? I bet that is very easily googlable. it's even the first when googling sqlite3 class php.net/manual/en/class.sqlite3.php Commented Dec 9, 2014 at 3:45
  • as for the confusion, the error message is very clear: SQLite3::__construct() this refers to the __construct() method of the sqlite3 class. expects at least 1 parameter ... 0 given ... If those english words do confuse you, I suggest you take some english classes before further developping :) Commented Dec 9, 2014 at 3:48

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, I'll try this. I'm sorry I was so confused about this, I generally understand classes from other languages, but for some reason I just can't seem to grasp it with this project in the same way. I'll keep at it though.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.