Mafia Game Monday (MGM) – MYSQL Depreciation

August 25, 2014

For MGM today, I am discussing about a BIG issue for many mafia game owners that is brewing if not currently already happening for some of you: MYSQL is going away in PHP! *SCREAMS* Don’t worry, it is not the end of the world, but will require some background knowledge as well as knowledge of what to do in order to prepare yourself for the inevitable. The LAST thing you would want is your site no longer working!

What does this mean for MYSQL users?
Basically, this means that as of PHP 5.5.0, the MYSQL extension will no longer be supported and will be depreciated.

What should you do as a replacement?
You can either use the mysqli extension (http://us1.php.net/manual/en/book.mysqli.php) or PDO (http://us1.php.net/manual/en/ref.pdo-mysql.php) instead.

What is the timeline for this depreciation?
Some users may already be experiencing this problem (as PHP 5.5 has been released); however, for those of you still running on older versions of PHP, this issue has not yet impacted you. The date of impact would depend on the timeline of the upgrade of PHP on your own server or the web hosting provider; however, I would suggest changing your code ASAP in order to prepare for this depreciation.

This is also a reminder to ALL programmers out there that technology changes rapidly, and as a programmer, we have to be able to adapt as well as make the necessary changes in order to keep up with the new standard technology.

That’s all for now, until next time…keep that tech gear ticking.

~Goliath7470

School is Returning…

August 21, 2014

Hello all!

So for many students young and old (including myself!), school is going to be back in session for the upcoming year if it has not started already for some of you. What does this mean? That means that time management becomes extremely important! Remember, balance is needed in order to not run you down, so how do you find time to do all of your work yet also give yourself time for your social life? Well, ask me this question, and I always say these tips in order to do that:

  1. Start Any Project/Assignment Early
  2. It would greatly surprise you how effective this tip is. If you start early, that will give you plenty of time to complete this project. Not only that, but this will also allow you to socialize if you need a break from the project without having to worry about completing the project on time! Yay, socializing! 🙂

  3. Do NOT Substitute Work for Play!
  4. This tip is simple. If you have an assignment or project due tomorrow you have to finish, do not trade a failing grade to party! Trust me, you will be extremely happy and thanking yourself down the road for not going to that party. Besides, there will be plenty of other parties when you don’t have a project due the next day to finish!

  5. Do NOT Overwork!
  6. If you are like me, you like to take on many new things no matter what else you are doing, which also includes helping other people. Well, when you have something very important such as school return into your life, school becomes a priority! If you have school or work to do when someone asks for help, unless it is an absolute emergency, your friend(s) will understand if you are unable to help them due to a school project or assignment that you have to work on. If you try to help everyone out with school in your life, you will burn yourself out!

  7. Use Your Time Wisely!
  8. If you do not read any of the other tips I have mentioned, just read this one. Use the time to your advantage! Make sure you give yourself time to work, play, as well as for just yourself!

These are some basic tips that I follow in order to make sure that I give myself time for work AND play. After all, I feel like I am working constantly…maybe I need to get out a little more…

Anyways, that’s all for now, until next time…keep that tech gear ticking.

~Goliath7470

Mafia Game Monday (MGM) – Database Normalization

August 18, 2014

So, last time on MGM, I discussed about database optimization. Well, in order to have full database optimization, there is something that will have to be done, which is: Database Normalization.

What Is It?

Database normalization is an organizing process of which you are eliminating redundancy as much as possible. This includes tables, fields, and all of the data in general. This also will ensure that all the data is stream-lined, which means that all core data can be easily linked to its corresponding data, and so on.

How Do You Normalize Your Data?

The simple answer is to make sure that there are absolutely no redundancies, duplication, or anomalies in your data. However, there is a process that you can go through in order to fully normalize your data.

  1. First Normal Form (1NF)
  2. First normal form is fairly simple. In order to achieve 1NF, make sure that ALL columns in your table only have one value in them. Basically, this means that separate all columns in your table that have multiple values in them. In order to do this, put the multi-value column into a new table using the key of the original table as the key of the new table. This will satisfy 1NF.

  3. Second Normal Form (2NF)
  4. Second normal form is a little more complicated. In order to achieve 2NF, make sure that no non-prime attributes are functionally dependent on a partial key. What does this mean in non-technical terms? This means that for any column that is not a key, that value should not be dependent (directly connected) to a partial key. So, take for example the following relational table below:
    CAR_SALE(Car#, Date_Sold, Salesperson#, Commission%, Discount_Amt)

    Now, if you take a look at the table, what’s the first connection you see in the data? I see: Salesperson# and Commission% right off the bat. So, in order to satisfy 2NF, we separate these values:

    SALES_PERSON(Salesperson#, Commission%)

    ..and the original table:

    CAR_SALE(Car#, Date_Sold, Salesperson#, Discount_Amt)

    Notice how I separated the Commission% from CAR_SALE, but still kept Salesperson# in CAR_SALE? The key value remains in the original table in order to establish a Foreign Key, which links these two tables together.

    Now, with this completed, 2NF has been satisfied.

  5. Third Normal Form
  6. Third normal form is pretty similar to second normal form. In order to achieve 3NF, make sure that no non-prime attributes are functionally dependent on another non-prime attribute. So, basically this means that no non-key attribute should be directly associated with another non-key attribute. So, how does this look? Take for example the two tables that we created after satisfying 2NF:

    CAR_SALE(Car#, Date_Sold, Salesperson#, Discount_Amt)
    SALES_PERSON(Salesperson#, Discount_Amt)

    Now, do you see any connection for any attributes that are not underlined? I do: Date_Sold and Discount_Amt in CAR_SALE. How are these related? Well, thinking of this as a database for car sales, managers would want to keep track of the discount amounts that were given out per day to track said discounts on a quarterly basis. So, for this example, we have to separate those two attributes into their own table:

    DATE_DISCOUNT(Date_Sold, Discount_Amt)

    and the other two tables:

    SALES_PERSON(Salesperson#, Commission%)
    CAR_SALE(Car#, Date_Sold, Salesperson#)

    Now with this complete, we have satisfied 3NF.

There of course are more normal forms than this, but by following these basic normal form steps, your tables will be approximately 85% normalized. To view more normal forms, check out here: http://en.wikipedia.org/wiki/Database_normalization (yes I know it’s wikipedia, but other sites that I looked at froze up my PC).

If you have questions or comments about database normalization, feel free to contact me! I will be more than happy to answer/respond to any questions/comments that you may have. 🙂

That’s all for now, until next time…keep that tech gear ticking.

~Goliath7470

Mafia Game Monday (MGM) – Database Optimization

August 4, 2014

Hey all,

I have been developing mafia style text-based games for approximately six years now, and I have found one very common trait amongst most of them. That is: lack of database optimization.

When you have a database, you should not have one table with almost 100 columns in it to be queried each and every time you load a page. That takes a long time to load all of that information just for a small subset of that data. So the immediate solution would be to make the tables much smaller and query all of those tables, right? Well, not necessarily. This is based off of what the particular use and need of those tables are. If say there’s a user’s table with general information on it, then sure, that can be a table. If there’s stats in that table, maybe split that up and have a table just for the user’s stats.

Why am I telling you all of this? Well, it goes with the territory of owning a mafia game. You will be querying the database many, many times throughout the course of the game, and you want those queries to return as fast as possible; however, with every query call to the database, that’s more time than simply using results that you have already received. So, as with everything, you have to find that balance in order to have your game perform at its best. So, in lieu of that, here are a few guidelines for good database optimization:

1) Split up the obvious information differences into their own tables

If say you currently have one table for all of the user’s information (including user’s stats), then the stats should be split up from the other information into its own table.

2) No tables with 50+ columns in them

This is simply an easy guideline to follow. If you have a table that has more than 50 columns, split it up somehow. A query that returns that much information will take a much longer time to run than say two queries of a much smaller data set.

3) Run some performance tests!

If you’re not sure whether your queries are efficient, run a performance test! Check how long it takes to run those queries. PHPMyAdmin and other database management tools have options to run queries on their own in order to check for performance.To do a performance test on your queries, you can do one (or more) of the following:

– Run Queries Separately in PHPMyAdmin
You can do this by going to the “SQL” tab in your database and run the desired query.

– Place microtime(true) functions on either side of the query and subtract the difference
PHP has a microtime(true) function that you can use to time anything from a timestamp to a query. Call the microtime(true) function and set to a variable (say $a) before running a query, run the query, and then set microtime(true) again (to $b this time). Then, all you have to do from there is subtract. A code block is below of an example. With this example, $b at the last line will have the time that you are looking for:


$a = microtime(true);
$result = ("QUERY GOES HERE");
$b = microtime(true);
$b = $b - $a;
echo 'It took ' . $b . 'seconds to run this query.';

Why did I pick microtime? I picked microtime because it will be more accurate than the time() function, as it will most likely take less than a second to run. For more on microtime() function, check out here: http://php.net/manual/en/function.microtime.php.

– Write Triggers (Advanced)
For those advanced SQL users, you can always write a couple triggers (one before accessing data and another after accessing data) that will achieve similar results to the other methods; however, with triggers, you can make triggers apply to specific tables, especially those of which you are more concerned about. With those triggers, you can also always have them give you data logs of information, which you can then use to make your own analysis of the performance of said query(ies). For more information on triggers, check out here: http://dev.mysql.com/doc/refman/5.0/en/triggers.html.

If you have any other comments or suggestions as to how to fully optimize your queries, please leave some feedback in the comments section or contact me! 🙂

That’s all for now, until next time…keep that tech gear ticking.

~Goliath7470