PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I am trying to create a database->table->field model and things are not going too well. Basically the field class does not inherit the $_table variable from the table class so the $_table variable contains no value. But everything else works.
Hmm... I guess I confused the parent:: bit. You should be able to use $this->_table now that you've removed the redeclaration.
I'm not sure I understand why Field extends Table. A field isn't a Table. A Table is made of one or more fields however, but it's composed of fields, not a descendant of one.
It returns FALSE because fetchSingle returns FALSE because it is trying to run the following query:
SELECT `username` FROM `` LIMIT 1
As you can see by that, {$_table} is NULL, no value has been set and this is causing the query to fail, this is because the {$_table} variable is not being passed to the parent class. For what ever reason which I don't know, it seems strange to me because it can pass the {$_table} variable value from the Table class to the MysqliAccess but not from the Field class to the MysqliAccess class.
Bon Bon wrote:It returns FALSE because fetchSingle returns FALSE because it is trying to run the following query:
SELECT `username` FROM `` LIMIT 1
As you can see by that, {$_table} is NULL, no value has been set and this is causing the query to fail, this is because the {$_table} variable is not being passed to the parent class. For what ever reason which I don't know, it seems strange to me because it can pass the {$_table} variable value from the Table class to the MysqliAccess but not from the Field class to the MysqliAccess class.
I agree with ~feyd that your types make no sense. A field is not a table so don't subclass table to make one. This is one of the most common mistakes newcomers to OOP make (in all OO languages).
The field name is not empty, it is the table name and that solution would do nothing to solve the problem.
The problem lies with the referencing of variables between 3 classes.
This is what I want to happen:
class 1 -> class 2 -> class 3
class 1 <- class 2 <- class 3
This is what happens:
class 1 -> class 2 -> class 3
class 1 <- class 2
class 1 <- class 3
I done some testing and using static variables I got the referencing to work using static variables but then this meant that I could only have 1 Table class and 1 Field class.
Now after I rethink I understand that I should not be extending classes like this, each class should have its own functionality and maybe sorting out what functions belong to which class might help solve the problem.
I will try splitting the classes, but in the future if I have the same problem but it made sense to pass the variable between 3 classes, each extending the parent, then I would still need a solution if anyone knows one?