PHP/Mysql browser based game

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
cxn
Posts: 6
Joined: Mon Apr 09, 2012 8:58 pm

PHP/Mysql browser based game

Post by cxn »

Hey guys

I'm working on my own little project, just created login / registration page! For now my intent is to build a crimes page, steal page.. basic mafia page stuff to be honest. Before I tackle these pages I have a few questions:

I noticed in Hall's tutorials that he doesn't use PDO or OOP. I know a bit of PDO so I'm going to try and integrate this in my programming (also for security reasons). However, I'm not at all familiar with OOP and was wondering if it's the standard nowadays? If not, what would you recommend to have simplified scripts? A lot of functions I bet?

Next I want to know if it's smart to make queries every time money changes (or exp, ..) or would it be best to store this in a variable until a session expires? I bet this isn't smart since a session can expire because a user has been idle for too long, instead of pressing the log out button (which would store the vars in the database (updating cash, exp etc)).

I got some more questions I think but I have no clue for a sec, too baked my bad! Hope this is clear :-) Thanks
User avatar
Chris
Posts: 1581
Joined: Wed Sep 30, 2009 7:22 pm

Re: PHP/Mysql browser based game

Post by Chris »

Don't store important things in sessions. They can sometimes mess around, especially if the client deletes their cookies or whatnot. OOP I guess is the standard nowadays.

You might want to check out an MVC framework if you are going down the OOP route.
Fighting for peace is declaring war on war. If you want peace be peaceful.
cxn
Posts: 6
Joined: Mon Apr 09, 2012 8:58 pm

Re: PHP/Mysql browser based game

Post by cxn »

Chris wrote:Don't store important things in sessions. They can sometimes mess around, especially if the client deletes their cookies or whatnot. OOP I guess is the standard nowadays.

You might want to check out an MVC framework if you are going down the OOP route.

Ok I see, so the best thing to do is to do queries, and each time?

I just googled MVC framework, looks demotivating haha! I'll try to read up tomorrow. By the way, do you also suggest PDO above prepared statements with mysqli or regular mysql?

Thanks
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: PHP/Mysql browser based game

Post by Jackolantern »

MySQLi > MySQL extensions, everytime, for everything. MySQLi extension is the far more advanced, efficient and secure successor to MySQL extension. If the MySQL extension had not been so important to basically all PHP development, it would basically be deprecated (marked for people to stop using, and eventual removal) today. Due to its importance, however, it will likely never be deprecated as to not break older software.
The indelible lord of tl;dr
User avatar
Verahta
Posts: 440
Joined: Wed Aug 24, 2011 1:50 am

Re: PHP/Mysql browser based game

Post by Verahta »

how do you know if you are using the old MySQL or newer MySQLi?
"In order to understand recursion, one must first understand recursion".
brockfanning
Posts: 10
Joined: Wed Apr 11, 2012 9:09 pm

Re: PHP/Mysql browser based game

Post by brockfanning »

If you're using PHP, you should be able to see that info in a phpinfo page, like:

Code: Select all

<?php phpinfo() ?>
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: PHP/Mysql browser based game

Post by Jackolantern »

Well, both are always available in all semi-current PHP versions and newer. If you are using the older MySQL extension, you will be using procedural functions like:

Code: Select all

mysql_some_thing(); 
You can instead use the newerMySQLi extensions, and the procedural functions will look like:

Code: Select all

mysqli_some_thing(); 
The indelible lord of tl;dr
User avatar
Verahta
Posts: 440
Joined: Wed Aug 24, 2011 1:50 am

Re: PHP/Mysql browser based game

Post by Verahta »

Thanks guys, I checked my PHP Info page and I do seem to have both:

MySQL Support enabled
MysqlI Support enabled
mysqlnd enabled
PDO Driver for MySQL enabled


And sorry for taking your thread slightly off-topic OP!
"In order to understand recursion, one must first understand recursion".
Xaleph
Posts: 897
Joined: Mon Feb 07, 2011 2:55 am

Re: PHP/Mysql browser based game

Post by Xaleph »

PDO is actually the way to go. In fact, MySQLi is deprecated as of yet. Instead, you should use PDO. PDO is the "true" OO way to go and it`s the safer bet over MySQL(i). However, as it turns out, more then 60% of all PHP developers working with MySQL still just write regular queries using the default MySQL functions.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: PHP/Mysql browser based game

Post by Jackolantern »

Actually, MySQLi stacks up decently well to PDO and it is not going to be deprecated in the near future, as can be seen on PHP's API comparison matrix. I usually recommend MySQLi right off the bat here because it can be used procedurally or OO, which makes it much more appropriate for beginning programmers.

And honestly, most advanced PHP coding is going to be done with an ORM solution or at least a framework which will take the responsibility away from directly interacting with the database extension to create a generic interface.
The indelible lord of tl;dr
Post Reply

Return to “Beginner Help and Support”