Creating Google Calendar Events with PHP

Many small businesses are now using the extensive Google Apps for Business framework to manage many of their daily activities. However due to the increase of Cloud Applications being programmed as well to assist this businesses, sometimes they have to be importing their online application information into their Google Apps. With the available API’s however this has not to be necessarily the case.

Using the new Google Calendar API and the following PHP code you can easily create events dynamically when they are generated in your cloud business application. Please be aware than in order to connect through their API you will need to have Zend installed on your server.

// Load required libraries
$path = 'Zend/Gdata';
$oldPath = set_include_path(get_include_path() . PATH_SEPARATOR . $path);
require_once 'Zend/Loader.php';

class google {
	public $client;
	public $service;

	function createCalendarEvent( ) {
		// Authentication with Google
		$user = '';
		$pass = 'userPass';
        // Load required libraries
		 // predefined service name for calendar
		$serviceName = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
		$this->client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $serviceName);
		$this->service = new Zend_Gdata_Calendar( $this->client );
		// get time
        $this->eventStart = "07:00:00";
        $this->eventEnd = "08:30:00";
		// Create a new event to add required parameters
		$event = $this->service->newEventEntry();
		// Create a new title for your calendar event
		$event->title = $this->service->newTitle( 'My First Google API Interaction' );
		// Set a location for your event
		$eventAddress = '123 Test St, Chula Vista';
		$event->where = array( $this->service->newWhere( $eventAddress  ) );
		// You can also add aditional information to your appoitnment
		$event->content = $this->service->newContent( 'Extra event information');
		$when = $this->service->newWhen();
		// Set start and end times
		$eventInfo = '2008-09-08';
		// 2008-09-08T22:47:31-07:00 (For Pacific Times)
		$when->startTime = $eventInfo . "T" . $this->eventStart . "-07:00";
		$when->endTime = $eventInfo . "T" . $this->eventEnd . "-07:00";
		// Set the when attribute for the event
		$event->when = array($when);
		// Create the event on google server
		$newEvent = $this->service->insertEvent($event);
		// URI of the new event which can be saved locally for later use
		$eventUri = $newEvent->id->text;


New Web Sites Do Not Validate

HTML and CSS Validation is a tool that was created in the beginning of the World Wide Web to make sure that web sites were constructed correctly. Many times when creating projects using new technologies, for multiple devices or that use third party applications we come to the problem that it does not validate according to the W3C standard. There are many developers and clients that react in a bad way when they see errors when validating and believe that the application still has bugs in it. Many time developers have to go back and change features just to make the site get a perfect score. Many times this makes the development time longer and the project more expensive. Developers and clients have to remember that validation is only a tool and nothing more than that, and while we do need to follow the standards set by the W3C we also have to make sure that usability and functionality are our top priority.

Usability over Technicalities

We always have to keep in mind that everything that we develop is intended for a person and not for a machine. Usability and Functionality for the target user of the application is the goal that we always try to achieve. While robots from search engines might crawl the application, we have to remember they are not our main audience. We also have to keep in mind that Google does not take validation as a ranking factor. You can see more about Google’s stand on this matter in the following video made by Matt Cuts for the Google Webmaster Forum:

When using many of the newer CSS3 techniques there will be an error created in the validation tool. For example when using border-radius that help us give rounded corners to our backgrounds. To go around this the designer has to design the curves and the developer implements them, which will take longer that using CSS3. We have to keep in mind that cases like this we have to always put user usability over irrelevant technicalities.

Validation is Irrelevant yet Important

While your validation score does not affect how search engine see you, it might still give you an extra boost in search engine optimization or SEO when the algorithm is looking at the web page overall usability. Validation as well still an important tool to review when working on a project. This tool will help you find unclosed tags and improperly nested div’s, extra semicolons, among other things. There will always be the error from Google’s Analytics or from that jQuery slider but as long as the integrity of the structure is impeccable you do not have to worry about the validation score from the W3C Tool. Remember that the score is only there to help you build a useable application; there is no target score you want to achieve just as long as you get 100% in usability with your target audience.

Please feel free to leave any questions or comments below.

Import CSV Files into a MySQL Database

Web Developer have to face a large amount of obstacles in their every day tasks in order to complete them. There are some thing that are easier to complete than other but a little bit of help can make a big difference when it comes down to finishing on time. Importing a CSV file into a MySQL database is often needed when creating projects for new clients. This is because they will use a variety of desktop software and they will probably tell you, “Here you go” when it comes to geting the data. To your advantage most of this applications have some way of exporting their data into Comma Separated Value files or CSV. Basically it’s a file that has a layout similar to a spreadsheet but instead of boxes for columns you have a coma separating the fields. In the same way in lieu of rows you will have a new line in the document.

The first step is to get that file from the customer or from it’s source and upload it into your server. After this you will need to access your server’s command line via an application like Putty and start your MySQL server.

$ mysql -h localhost -u root -ppassword

You will need to create your database with the fields that you will be needing. once your database has been set up you can import the data from your CSV file into your MySQL database. Here is the command that you will require in order to import the information into your database table.

load data local infile ''
into table phpdev.gc_cities
fields terminated by ','
enclosed by '"'
lines terminated by '\n'
(zipCode, city, state, county, areaCode);

In the first line of the command is where the location to your Comma Separated Values or CSV file is located at. The second line is the table that you want the information to go into. The third line is telling your MySQL server that the values are separated by comas. In the same way the fourth line is describing how the values are enclosed by single quotes. The fifth line is telling your server that your row ends when the line end. Finally the sixth lane is the fields in your database table. They need to be aligned with the order of your file for example if your files is ID, Price, Description then your locations will be (id, price, description) and so on.

Often there are times that the above command will not work. This is due to the fact that this option is considered to be a big security risk. Some hosting companies like Media Temple are disabling this by default so you will need to make a couple of small changes in order for it to work.

You will have to locate your MySQL configuration file which is usually located at ‘etc/my.cnf’ and comment out the line that prevents the import. You will have to do this while being a root user in your server, if not it will only allow you to read the file but not to reconfigure it. The line that you are looking for is:


You will have to comment it by adding a “#’ sign at the beginning of the line like:


You can learn more about this on the MySQL Documents. After you have completed the change you will need to restart the MySQL server and then do the process once more. The command to restart the server is:

service mysql restart

Hope that this helps any web developers out there. Please feel free to leave any comments, questions or suggestions down below and we will be happy to assist you.