2

Alright, so after years of feeling that I've been doing it the wrong way, what is the best way to interact with a MySQL database, using PHP. Going to start off small-scale, but eventually hoping to grow large scale.

I'd love to be able to use objects, like such

$book = new Book(1342);
echo $book->title;

So, what is the best way to go about using something of a data abstraction layer, or what can I use to accomplish what I am looking towards?

bcosca
  • 17,371
  • 5
  • 40
  • 51
Chiggins
  • 8,197
  • 22
  • 56
  • 81

3 Answers3

4

What you are looking for is an ORM library.

Here is a thread that might help you ~> Good PHP ORM Library?

Community
  • 1
  • 1
letronje
  • 9,002
  • 9
  • 45
  • 53
0

You're looking for is called Object Relational Model or ORM. If you're working in PHP check out doctrine: http://www.doctrine-project.org/projects/orm

It also might be worth looking into Ruby on Rails if you're going to be doing a lot of this type of interaction, rails has really nice ORMs.

Ken Struys
  • 1,789
  • 1
  • 10
  • 17
0

As a side note:

I would like to point out that most ORM frameworks advise against using object syntax for read-only data.

So while you are actually looking for what is known as an ORM framework (and I do recommend one - such as Doctrine), you will likely be using array syntax in the end for performance reasons.

Craige
  • 2,882
  • 2
  • 20
  • 28