Ask about general coding issues or problems here.
Moderators: macek, egami, gesf
by poweeuser » Tue Oct 02, 2012 10:28 am
I've signed up for a Lynda.com course that includes OO PHP application development having previously only worked on procedural applications. The course uses procedural code with function calls to implement a connection to an existing MySQL database and then advocates use of the same code as a method of a database class. The function version successfully makes use of connection constants such as database and username in an external 'include' file but the method version insists in having the constants defined in the same physical file otherwise it generates warnings about undeclared constants.
Why ? / how do I fix it?
-
poweeuser
- New php-forum User

-
- Posts: 2
- Joined: Tue Oct 02, 2012 7:37 am
by seandisanti » Tue Oct 02, 2012 11:29 am
I've gone through those same examples recently. the database.php requires config.php in the first line. That brings in the constants.
-
seandisanti
- php-forum Fan User

-
- Posts: 679
- Joined: Mon Oct 01, 2012 12:32 pm
by poweeuser » Tue Oct 02, 2012 12:17 pm
OK, I've learnt a valuable lesson, the require location in the database.php file has to be relative to the index.php not the database.php file itself ie '../includes/config.php' - which is not intuitive, nor mentioned in the course material
-
poweeuser
- New php-forum User

-
- Posts: 2
- Joined: Tue Oct 02, 2012 7:37 am
by seandisanti » Tue Oct 02, 2012 12:27 pm
at least you learned it now rather than working on a big project.
-
seandisanti
- php-forum Fan User

-
- Posts: 679
- Joined: Mon Oct 01, 2012 12:32 pm
Return to PHP coding => General
Who is online
Users browsing this forum: No registered users and 5 guests