Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to store objects from OOP on a database like MySQL

I've been working in Java lately, and I have OOP down. More recently I've been working on web based programming with jQuery, javascript, PHP, and most recently MySQL. With OOP its very easy to manage objects and read/write information about them. Now that I'm learning MySQL, I'm finding it hard to convert a simple OOP program to an online "program" that stores its data in a database. I've been playing around in Access, just so I can get a visual of the whole database, and can't seem to come to a good way of storing the data. For the purpose of learning this... here is a simple OOP class structure (Java) that I would like converted to a database (so to speak).

public class Tournament {

  ////////////////////////////////////////////
  //Variable Declaration
  ////////////////////////////////////////////
  Team[] theTeams;  //Array of Team Objects
  int numTeams;     //Number of Teams

  ////////////////////////////////////////////
  //Functions and stuff
  ////////////////////////////////////////////

}



public class Team {

  ////////////////////////////////////////////
  //Variable Declaration
  ////////////////////////////////////////////
  Player p1;        //Player 1
  Player p2;        //Player 2
  int teamNum;

  ////////////////////////////////////////////
  //Functions and stuff
  ////////////////////////////////////////////

}



public class Player {

  ////////////////////////////////////////////
  //Variable Declaration
  ////////////////////////////////////////////
  String fName;     //First Name
  String lName;     //Last Name

  ////////////////////////////////////////////
  //Functions and Stuff
  ////////////////////////////////////////////

}

For a database, would I want it something like this?

Relationships

Maybe I'm completely offbase with the whole idea. I'm not sure. If someone could let me know where I'm at, that would be great. All help's appreciated.

like image 689
mandelbug Avatar asked Dec 03 '25 23:12

mandelbug


1 Answers

You could use an ORM library like Doctrine.

like image 179
pdoherty926 Avatar answered Dec 05 '25 12:12

pdoherty926



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!