Problems with database methods in a class

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

poweeuser
New php-forum User
New php-forum User
Posts: 2
Joined: Tue Oct 02, 2012 7:37 am

Problems with database methods in a class

Postby 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?

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: Problems with database methods in a class

Postby 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.

poweeuser
New php-forum User
New php-forum User
Posts: 2
Joined: Tue Oct 02, 2012 7:37 am

Re: Problems with database methods in a class

Postby 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

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: Problems with database methods in a class

Postby seandisanti » Tue Oct 02, 2012 12:27 pm

at least you learned it now rather than working on a big project.


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 1 guest

cron