how to make class $db?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ganza
Forum Newbie
Posts: 19
Joined: Fri Nov 07, 2008 3:56 am

how to make class $db?

Post by ganza »

last time my friend teach me a lil bit of php...
but he teach me using his library and now i realize that i cannot use like $db->sql_fetchrowset() $db->sql_query()
is it possible all pros here teach me how to make class $db?

thanks
User avatar
Peter Anselmo
Forum Commoner
Posts: 58
Joined: Wed Feb 27, 2008 7:22 pm

Re: how to make class $db?

Post by Peter Anselmo »

What your friend was probably using (and what I use in my scripts) is what is called a "singleton" database class. Basically, once you define the class, it allows you to execute queries all over the place in your code without having to worry about whether or not you've called the mysql_connect() function already. It'll automatically open a connection if you haven't yet, and if you have, it will keep from opening multiple redundant connections.

....................

I'm not sure if that made any sense or not. If it did, I can explain more, but if it didn't, I would advise forgetting it and using three simple functions for a while for your database work.
mysql_connect()
mysql_select_db()
mysql_query()
Post Reply