Jump to content

Fetching Data from Database using PHP classes (OOP)


salmander

Recommended Posts

Hi, I am new to php OOP. I have developed few projects using procedural php.

I am converting my already existing php (procedural) project to php oop. As its a very small and basic project. So I thought that it would be a good practise for me to deal with the problems before actually touching big projects. Ok, so I have one database and one table in that database. I am making one class (class A) to connect to the database and fetch the data. And I want a separate class (class B) to format that data in a table form. Then class B will be called in the index.php page to display it.

I know I am not very good at explaining things....but I hope I have made my point clear. its a simple task but I need some experience programmers help to tell me what approach shall I take? Right now I can successfully able to to fetch one field from the database and return it. Thus when I call this function in other class (class B) its displaying it. In procedural php i used a while loop to fetch all the fields from the database and echo it. It was easier as the data is not travelling from one function or class to another class. Now I dont understand how to I fetch all the fields from the database and then pass it to another function or class.

 

Hope you understand what I am trying to say. Ask me if you need to clarify anything.

Thanks.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.