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 4078124
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:38:08+00:00 2026-05-20T17:38:08+00:00

I’m not sure what’s a better practice or a more real-world practice. I’m looking

  • 0

I’m not sure what’s a better practice or a more real-world practice. I’m looking to create a Catalog System from scratch, but unsure what the best approach would be.

I was thinking that I use objects when I need to display information like, info.php?id=100. Have code like this for displaying

Game.class.php file

class Game {
    private $name;
    private $type;
    private $database;

    public function __construct($database, $id) {
        $information = $database->select($id); // returns mysql_fetch_array

        $this->database = $database;
        $this->setName($information['name']);
        $this->setType($information['type']);
    }

    public function __destruct() {
        unset($this->name);
        ...
    }
    ...
    private function setName($name) {
        $this->name = $name;
    }
    ...
    public function getName() {
        return $this->name;
    }
    ...
    public function addToDatabase() {
        // stuff here to check if it exists in the database or not
        $database->insert('test', array('id' => '', 'name' => $this->name, 'type' => $this->type));
    }
}

info.php?id=100 file

// already have __autload()

$id = sanitize($_POST['id']);
$item = new Game($db, $id);
echo "Item name: " . $item->getName() . " <br />";

But I don’t really need to create objects for like when I add or update things add.php?name=XMen&type=GameBoy

I wouldn’t want to do this:

$name = sanitize($_POST['name']); // sanitize
$type = sanitize($_POST['type']); // sanitize
$newObject = new Game($name, $type);
$newObject->addToDatabase();

I should instead I should just skip creating an object and just insert directly

$name = sanitize($_POST['name']); // sanitize
$type = sanitize($_POST['type']); // sanitize
$sql = "INSERT INTO test ('id', 'name', 'type') VALUES ('', $name, $type)";
mysql_query($sql);

or if I had a database class

$name = sanitize($_POST['name']); // sanitize
$type = sanitize($_POST['type']); // sanitize
$db->insert('test', array('id' => '', 'name' => $name, 'type' => $type));
  • 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. Editorial Team
    Editorial Team
    2026-05-20T17:38:09+00:00Added an answer on May 20, 2026 at 5:38 pm

    To get complete abstraction you might look into 3rd-party ORMs. At the very, very least you should create your own database class. I usually use a Singleton design pattern if I only plan on having one database connection.

    You don’t want raw SQL statements all over the place because you may need to switch to and/or support different versions of MySQL or even a different database all together. It’d be easier to replace a single database management object than to fix all those queries throughout your code.

    One of my database classes is much like that third option you posted and it works quite well. It has a bunch of conveniences like insertArray(), getOneRow(), getOne(), getOneFromAllRows(), executeExternalFile(), and an iteratable result set for all SELECT-like queries.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I want to count how many characters a certain string has in PHP, but
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
In my XML file chapters tag has more chapter tag.i need to display chapters
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but

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.