This week I found myself needing to restore a MySQL database on a Windows server, the host of which left me no access to MySQL other than the ability to create a database and users. If you find yourself in the same boat, here is a PHP script I used to perform my restore:


<?php

$myFile = 'backupFileName.sql';
$myHost = 'hostName--usually localhost';
$username = 'username';
$myPass = 'password';
$myDB = 'nameOfDb';

mysql_connect($myHost, $username, $myPass) or die('Back to the drawing board: ' . mysql_error());
mysql_select_db($myDB) or die('Back to the drawing board: ' . mysql_error());

$sqlEntry = '';
$rawFileData = file($myFile);

foreach ($rawFileData as $entry)
{
// strip out comments
if (substr($entry, 0, 2) == '--' || $entry == '')
continue;

// add line to the sql statement
$sqlEntry .= $entry;

// if line ends with semicolon then you know it completes the sql statement
// go ahead and execute the query and reset the sql variable
if (substr(trim($entry), -1, 1) == ';')
{
mysql_query($sqlEntry) or print('Query did not execute properly: \'' . $sqlEntry . '\': ' . mysql_error());
$sqlEntry = '';
}
}

?>

Just change the values for the variables $myHost, $myFile, $username, $myPass, and $myDB and your set. If your backup file is not in the same folder as this script make sure you include at least the relative path in the value.
Hope this helps!

This is a project I’ve been working on, and I plan to make it live in the next few weeks. The site consists of some free business tools, such as a statistics calculator and a mortgage calculator. As I mentioned, these tools are totally free, and no registration is required to use them. Users can, however, join the site and take advantage of some nice features:

  1. A report wizzard for generating charts and graphs from their data
  2. A Microsoft Office export wizzard, for exporting data to Excel or Access
  3. A data file uploader, for when there’s just too much data to enter in by hand

I look forward to getting this site up and running, and will update this post when it’s live.

Customer Management Studio

February 12, 2010

This is what I’ve named my QuickBooks app. I’ve now completed the first phase, and I’m well into the second. The app now provides:

  1. Order form
  2. Order tracking
  3. Customer/Order report wizzard
  4. Invoicing Module

All I have left at this point is to create the inventory module and integrate it with the existing project.

Quickbooks SDK: Part II

December 1, 2009

I’ve gotten a little bit accomplished since I’ve dusted off my code at my last post. I’m nearly finished with what I call the ‘first stage’ of the project. My application connects with Quickbooks, retrieves all customer information not already in the database, and copies it to the customer table. There is a bit field in this table set to flag customers who have previous orders. With the customers stored in the application’s database, the auto-fill form comes into play to make order-taking much more efficient. All existing customer information automatically populates the form, leaving order specific fields left to be filled in. Once the order is taken, a ‘commit’ button prints two copies of the order, one for the driver to perform the duty, and another for office work, which may contain sensitive data. At this point the order information is saved to the ‘orders’ table, which shares a one-to-many relationship with the ‘customer’ table based on a shared CustomerID field.

So, that’s where I’m at right now. I will have to say that the most interesting part up to this point was the task of creating the print job. Gone are the days of the ‘Printer.Print()’ method in Visual Basic (while I despise VB, I did find myself wishing this capability was still at my fingertips). I basically created a ‘Printer’ class that inherits from ‘PrintDocument’. I instantiate two instances of this class from my frmMain class, one for each print job. I went back and forth on whether to take it a step further and create properties to set regions on the page to coincide with the info I needed to include, or to just text-format the output old school style. Ultimately I decided to go old school because, hey, why not? It works and it saved me some time. My next task is to implement a reporting system to run queries on the database.

Uhhh….Now where was I???

November 3, 2009

OK. It’s been a little while since my “Quickbooks SDK: Part I” post, reason being the project was put on hold. I had made some decent progress on it, so now I get to go back through my code and figure out what it does! A slight exaggeration, perhaps. I’m glad to get started up again, and plan to post frequently concerning it.

My skin is crawling just thinking about this guy.

My skin is crawling just thinking about this guy.

I do NOT like spiders. I mean, they can be anywhere! I saw on the Discovery Channel that at any given time in your life you are ALWAYS within seven feet of a spider! Now, that may be total BS, but I’m beginning to think it may be true. Two days ago I sat with a man I work with in a doctor’s office for over an hour. He was outside working and was bitten by a Black Widow spider. Luckily he was alright, it seems he killed the spider before it was able to inject any serious amount of venom into his neck. This occurred on Wednesday.

Yesterday, Thursday, -THE VERY NEXT DAY- I cleaned out an office I had been sharing with my boss. He is a total pig, and I had come to the point where either I was getting another office or his would be cleaned. He agreed to help me clean it, so we embarked on what we thought to be a relatively nonhazardous mission.

Now, I should point out that his office contained a conglomeration of items, few of which had even been moved in the last three years. There were layers upon layers of papers, car parts, Big Mac boxes, and molded ammunition. About halfway through our job we were feeling pretty good. We had made three trips to the dumpster, and you could actually see the floor.

As I began vacuuming the floor, my eyes began to detect tiny red dots moving along the baseboards around the room. I thought, “Whoa, those are some really big chiggers! They must be radio-active!” But alas, these were no chiggers! These were adolescent black widows!!!! I wasn’t sure what to do at this point. I didn’t want to start smashing them because I was afraid one of them would somehow get on me if I got too close. I did what any arachnaphobic man would do… I let out a shrill, girl-like yelp and sucked them up with my vacuum.

Great. Now I’m standing there with a vacuum, a bagless vacuum mind you, with dozens of poisonous spiders therein. I began to trot to the dumpster to chunk the perfectly good vacuum when, from behind me I hear my seven-foot boss begin to yell, “Oh my God! Ahh! Big spider!!! BIG SPIDER!!!

I dropped the vacuum to return to the spider nest. I had to see this creature that had made my boss involuntarily release his bladder. I walked in the room and I saw him. He was crawling on the rim of the trash can and seemed to be issuing a challenge to everyone present. This, clearly, was the alpha-spider. He was easily the size of a dinner plate, and he seemed to be smirking at me as he spit tobacco juice on the floor. My boss tried to swat him to the floor, but the spider blocked his jab and countered with a roundhouse. An intense struggle ensued, and it became clear that this was a fight for more than bragging rights, this was for survival.

My boss was fatigued and lay slumped in the corner, and the spider had just thrown me against a wall. I lay there feeling quite helpless. The spider approached me, and in his eyes I saw murderous intentions. He began to crouch, preparing for a tobi-kekomi which surely would have meant my demise. Suddenly, the spider began to stumble, gasping for breath. At first he seemed confused, but that quickly gave way to fear. Then I realized what had happened. The spider had swallowed his wad of tobacco! As the spider lay there choking to death, I realized how near to death I had been. I immediately ran outside to call my family and tell them I loved them.

There are two messages you should get from this story:

  1. I do NOT like spiders, and
  2. You are ALWAYS within seven feet of a spider!

Quickbooks SDK: Part I

October 1, 2009

One of the projects I am now working on is a Quickbooks application that is designed to make the client’s order-taking and billing process more efficient. My customer is a small company who cannot afford a custom software package that is tailored to their specific needs, but find the inventory control and time tracking offered by Quickbooks to be little help to their company. My app connects to Quickbooks and syncs customer, billing, and invoice information with a separate database that tracks their inventory and orders, thus eliminating the need to enter the same information twice. It also provides an auto-fill form for order taking, and walks through the billing process step-by-step until the billing cycle is completed. The process begins in Quickbooks and, eventually, ends with an invoice in Quickbooks. I will be posting frequently about this project, if for no other reason to document my progress and allow myself a journal to look back on if my path gets fuzzy. I am writing this in C# using QBFC 8.0. I am now in the beginning stages, but I hope to move quickly on this project as I am anxious to get my hands dirty. Stay tuned…

Encounter God Ministries

September 28, 2009

I have had the pleasure of working with Chuck Graham of Encounter God Ministries for the past several weeks. We are putting together ‘Encounters’ for Christian men who love Christ and want to serve Him, but have some areas of their lives that they can’t seem to gain victory in. It is an intense weekend that will put the fire and passion back into your relationship with Christ. Check out the website at EncounterGodMinistries.net for information.

God’s Chisel

September 28, 2009

This video pretty much speaks for itself. Definitely worth checking out.

Click to view Video Preview