random1 Posted August 6, 2009 Share Posted August 6, 2009 Hi All, I have a OO class in PHP in the file 'database.php' called 'Database' that includes methods that make a database connection, close it etc... This class includes 2 main methods called 'executeQuery' and 'executePreparedStatement' (self explanatory). The 'database' class is included in my file called 'index.php' and I need other included classes such as 'user' to be able to use 'executeQuery' and 'executePreparedStatement'. In PHP how do you allow access to a mysqli object to another class? Can you simply pass it and then gain access to its methods? Link to comment https://forums.phpfreaks.com/topic/169026-oop-database-connection-class-help/ Share on other sites More sharing options...
trq Posted August 6, 2009 Share Posted August 6, 2009 You can either pass an instance of the database object to the constructor of the receiving object or if you don't mind tying your objects together too firmly you could simply instantiate the db object within the object that needs it. Link to comment https://forums.phpfreaks.com/topic/169026-oop-database-connection-class-help/#findComment-891824 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.