Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 168451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:27:21+00:00 2026-05-11T12:27:21+00:00

I have a chicken-egg problem. I would like too implement a system in PHP

  • 0

I have a chicken-egg problem. I would like too implement a system in PHP in a OOP way, in which two classes would play important roles: Database and Log. My idea was to build up the connection by the Database class, which would have public methods eg. runQuery(sUpdateQuery), doInsert(sInsert), etc. The Log class would writing logs through common methods just as like logMessage(message), logDatabaseQuery(sQuery) TO THE DATABASE. The problem comes now.

1: Inside the methods of the Database’s class I would like to be able to use the Log class’s logDatabaseQuery(sQuery)

2: This still would not be a big challenge if I would not like to use the Database class’s doInsert(sInsert) method inside the logDatabaseQuery method.

I would like to keep it simple – and just use one instance of the database connection object, and from the loggeras well, if it is possible.

For many people Singleton model would be the first idea to choose, but I definitely would like to use different solution.

So there would be two classes which would use each-other’s methods:

Database doInsert logDatabaseQuery

Log logDatabaseQuery doInsert

I would like to keep the Log methods separately (in the Log class), since later on it would have other methods for logging not just to the database, but to files or e-mails as well.

Any ideas, how this should / could be done in the nicest, OOP friendly way?

I was thinking about a common parent abstract class, or about using interfaces as well, but finally could not figure out the proper way 🙁

What I would like to know is a suggestion for a correct class hierarchy

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T12:27:22+00:00Added an answer on May 11, 2026 at 12:27 pm

    You have combined too many things together.

    The database can’t really depend on a logger which depends on the database. It isn’t good design.

    What you really have are two kinds of database access.

    Low-level access does ‘raw’ SQL.

    The logger can depend on this lower-level class. It doesn’t — itself — have raw SQL in it. It depends on a lower-level class.

    High-level access does application queries, it uses low-level access and the logger.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 114k
  • Answers 114k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer An example of one I saw was everyone in the… May 11, 2026 at 10:12 pm
  • Editorial Team
    Editorial Team added an answer I Think this is beacuse you didn't fetched the profile… May 11, 2026 at 10:12 pm
  • Editorial Team
    Editorial Team added an answer Here are some experiences I had while creating the same… May 11, 2026 at 10:12 pm

Related Questions

I'm designing a re-usable class library that contains 2 assemblies (amongst others) named core.xml.dll
I've got about 100 unit tests and with a coverage of %20, which I'm
I'm trying to get my head around TDD methodology and have run into -
I need to create a Firebird Database programmatically using DBExpress. I have done this

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.