Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
DB CLASS: laoding seperate ones if mysqli or mysql??
Old 01-29-2008, 12:23 PM DB CLASS: laoding seperate ones if mysqli or mysql??
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Hi,

im about to go about putting together a DB fucntion class, and im wondering about something.. i have a game script and it has two db class files one for mysqli and one for mysql and it includes them for which ever one is set so if u tell it it is mysqli it uses that etc... but why is it worth it?

and how could it be better done?
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
 
Register now for full access!
Old 01-29-2008, 03:24 PM Re: DB CLASS: laoding seperate ones if mysqli or mysql??
Extreme Talker

Posts: 182
Trades: 0
Hey, Dan!

Why is what worth it? Building a db wrapper class?

Many reasons: Flexibility, easy to update and edit the way your sql queries are handled, makes coding easier.

If you want to make a wrapper for your wrapper, so that you can easily switch between different databases, it would be best to create an abstract class for the wrapper of your wrappers ( if that makes sense )

abstract db class
-> mysql wrapper class
-> postgresql wrapper class

If you would like, I can code you up a simple example of a basic mysql wrapper for php.
bhgchris is offline
Reply With Quote
View Public Profile
 
Old 01-29-2008, 04:02 PM Re: DB CLASS: laoding seperate ones if mysqli or mysql??
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
o.0 ok... erm wrong end of stick.

i know why its a good idea to sue Classes (only just got the courage to attempt them...)

what i ment was having two classes one with all the mysql_ functions (for mysql 4 < and php < 4) and a mysqli_ funcs for php 5> and mysql 5>


anyways im doing it now and its not working...

i have the connection part changed over and it is connecting, but none of my queries are working... why?

(at the moment the queries are NOT using the class)

but shouldnt they still work?

ALSO when i make a query ($db->query()) do i have to have global $db; inside the function or is there a way to have it globalised by default?
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 01-29-2008, 04:26 PM Re: DB CLASS: laoding seperate ones if mysqli or mysql??
Extreme Talker

Posts: 182
Trades: 0
On a basic level, a class consists of methods and properties.

Methods are simply the functions, and properties are basically the global variables inside of the class.

Methods and properties can be accessed from within the class by using $this

class myClass
{
var $myProperty = 2;

function myMethod ( )
{
$result = $this->myProperty * 3;

return $result;
}

function anotherMethod ( )
{
$result = $this->myMethod ( );

echo $result;
}
}
bhgchris is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to DB CLASS: laoding seperate ones if mysqli or mysql??
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13521 seconds with 12 queries