Hi there,
I've been using some database abstraction layer(EzSQL, very nice) functions, which I included in my includes.php file, which is sort of a -must- header file in all of my PHP pages, like so:
-- includes.php
include(getenv("DOCUMENT_ROOT")."/shared/php/ezsql/ez_sql.php");
After that I have some functions in my includes.php file which use the class declared in ez_sql.php which I have previously included, like so:
-- again in includes.php
function display_list_of_actors($show_id) {
$actors_list = $db->get_row("SELECT actors FROM shows WHERE id = $show_id");
$actors = explode(",",$actors_list->actors);
$nArraySize = count($actors);
for($index=0; $index < $nArraySize; $index++)
{
if ($index < $narraysize | $index > 0) {
echo ", ";
}
$actor = $db->get_row("SELECT id,firstname,lastname FROM artists WHERE id = $actors[$index]");
echo "<a href=\"/artists/display_bio.php?id=".$actor->id."\">".$actor->firstname." ".$actor->lastname."</a>";
}
}
function display_artist_by_role($role,$show_id) {
switch ($role) {
case "director": {
$artist_id = $db->get_results("SELECT director FROM shows WHERE id = $show_id");
$artist = $db->get_results("SELECT firstname,lastname FROM artists WHERE id = $artist_id");
echo "<a href=\"/artist/display_bio.php?".$artist->id."\">".$artist->firstname." ".$artist->lastname."</a>";
}
}
}
After that, when I try to use the functions display_artist_by_role and display_list_of_actors in my PHP page, I get a "Fatal error: Call to a member function on a non-object in /.../www/shared/includes.php on line 34" which is the first line reffering to one of the functions declared in the ez_sql.php class file. Baaaaaaa.
I tried moving the "include(getenv("DOCUMENT_ROOT")."/shared/php/ezsql/ez_sql.php");" line into each of the functions instead of putting it at the top of the includes.php file, and then the first instance where I used either display_artist_by_role or display_list_of_actors worked fine, but the second one said I can't redeclare the class (reffering ofcourse to the include line being there in both of the functions).
What's a guy to do?
(Please don't make me learn classes... 🙁 )
Thanx