Learning PHP and MySQL – Good Books to Have

If you are serious about learning PHP and MySQL, you need good resources. There are many online tutorials and websites, and I have listed some really useful resources in a previous post. If you are like me and prefer to not read off a screen, and instead like to use a book, there are many excellent books out there that range from novice to expert level. I have collected what I believe to be some of the best books to have and added them my Programmers Store, so that they are in one easy place for you to find. So go ahead and check it out.

You can also find some on your library bookshelf for free, which is always better… free is good. The one that I am using is Beginning PHP5, Apache, and MySQL Web Development (Programmer to Programmer), and I love it. It starts you from scratch, although it does help to have some HTML/CSS knowledge. The Appendix has instructions on installing Apache, PHP, and MySQL, which came in really handy for me.

So check out the store!!

CMS’s – Another reason to master PHP

If you are interested in web development, then you’ve probably at some point discovered, dealt with, or cursed at a Content Management System (CMS). This is actually one of the main avenues through which I discovered, and decided to learn PHP. Installing a CMS and modding it to get it to look like you want, let alone work like you want it to, can be painful. It can also be fun… it’s all a matter of perspective. Using a CMS can save you a lot of time and effort in putting a website up. Depending on the application that you choose, using a CMS can also add a lot of functionality to your website with minimal coding effort and time on your part.

Many CMS frameworks are built on PHP, and having PHP skills goes a long way in helping you install, secure, and modify files so that you get the look, feel, and functionality that you are seeking.

There are many PHP-based Content Management Systems out there, and picking out one that works is often a matter of trial and error. I don’t want to dwell on the different CMSs in this post since they are too many to count, but a good place to look at and compare them is http://www.opensourcecms.com. You can test-drive a lot of them there, look at the admin panel, and determine if the CMS is what you’re looking for.

My recommendation is that you get yourself a free, or relatively cheap hosting account that offers PHP and mySQL. A good feature to have would be the ability to create subdomains. You can then use this account to test and play with CMS applications to your heart’s content, without any risk to your primary website. This is the approach that I use when testing and picking content management systems.

Hosting

For cheap hosting, I recommend Hasty Host because they have a great capacity plan that will allow you lots of space and bandwidth to set up different systems and test them out. If you want to use a free account, then I would recommend going with Byet Host. They offer you cpanel hosting, with 3 MySQL databases, and 5 additional subdomains.

Bear in mind that you’re going to need a MySQL database for each system you install, so the more the better. I prefer to shell out the $2.95 a month for Hasty Host because I get an unlimited number of MySQL databases, and unlimited subdomains. With the free hosting plans you will have to contend with ads on your page. However, with a plan like the one I have at Hasty Host, you are in full control, and if one of your CMS experiments takes off and you like what you’ve created, you don’t have to worry about stripping everything down, and starting again on an ad-free hosting account. You’ll already have you site set up and ready to go!

Domain Names

The other thing you may or may not need is a domain name. If you go with a free hosting plan, you won’t need a domain name unless you decide to use one, and you free hosting account allows you to. In most cases your account is a subdomain of their account, for example: myexperiments.myfreehost.com, or myfreehost.com/myexperiments. If you do go with a cheap hosting account such as Hasty Host, then you will need to purchase a domain name. I recommend always buying your domain names from established registrars, such as GoDaddy (www.GoDaddy.com).
Once you have your hosting account set up, you can start playing with the different content management systems to see what they have to offer.

Some Tips

  • If you want to test the applications side by side, create subdomains for each, so that you can compare features and functionality without the hassle of installing and uninstalling.
  • Name each subdomain with a meaningful name in case your experiment takes off and you decide to keep the website.
  • See if your hosting offers a script installer such as Fantastico, since this makes installing different CMSs easier.
  • You can use your account to test blogs, bulletin board scripts, and other scripts too!
  • Most CMS apps have user forums, which are always a good place to go for tips and help when you get stuck.

Have fun! And happy coding.


www.godaddy.com

PHP Resources

I am still working on the starting stages of PHP, with real life and other obligations interfering frequently, so progress has been a tad slow. However, I have been spending a lot of time on different websites and forums learning, and getting motivated. In this post I will share some of these useful links and resources, and will be adding them as I go, so keep an eye on the Useful Links and Resources category. The ordering of these links is pretty random and does not reflect any kind of ranking.

So here goes:

  • PHP Official website – This is the home of PHP, and your best source for information on bugs, updates, and PHP documentation. There is also an extensive faq, mailing lists, and a page of useful links. Definitely your best first stop for all things PHP.
  • Digital Point Forums – Webmaster forums with a section for PHP. This is an excellent site to join and ask questions about any coding problems, and to learn about web design and webmaster issues in general. Excellent responses from members.
  • Sitepoint Forums – Another excellent webmaster forum and great resource for anyone venturing into PHP. Very helpful place.
  • HypertextFever Forums – This is a new forum that’s really cool and shows great promise for being a great resource. It has a lot more of a personal feel to it. While the bigger more established forums are awesome, sometimes when you’re a novice you need a smaller setting so that you don’t feel too intimidated… I know I do. Great quality responses, and the owner of the forum is a PHP/MySQL guru, and responds fast and extensively to all questions, so this is a great place for anyone who wants to learn and grow.
  • Joe Watkins – PHP Programmer – This website is a bit more advanced but has useful PHP scripts and interesting tips and code. You can register and subscribe to the feed to get the latest posts.

There are numerous more and I will be adding them as I go, after I evaluate them. I may eventually build a link page to list them all. If you know any exceptional ones that should absolutely not be left out please feel free to leave a comment and I will add them to my growing list!

For now… happy coding!

Some database tools – phpMyAdmin and HeidiSQL

In my last post I talked about dealing with a .sql file from the command line. This worked well, but there are other ways to interact with your databases that are GUI based, and perhaps easier for someone accustomed to dealing with the GUI interface. The two that I am currently playing with are PHPMyAdmin and Heidi SQL. Both are free to download and use, keeping with my theme of using free tools and utilities whenever I possibly can.

phpMyAdmin is a tool written in PHP intended to handle the administration of MySQL over the Web. Currently it can create and drop databases, create/drop/alter tables, delete/edit/add fields, execute any SQL statement, manage keys on fields, manage privileges,export data into various formats and is available in 52 languages.

HeidiSQL is an easy-to-use interface and a "working-horse" for web-developers using the popular MySQL-Database. It allows you to manage and browse your databases and tables from an intuitive Windows® interface.

With HeidiSQL you will also be able to
* generate nice SQL-exports
* synchronize tables between two databases
* manage user-privileges
* import text-files
* export table-data as CSV, HTML and XML
* browse and edit table-data using a comfortable grid
* batch-insert ascii or binary files into tables
* write queries with syntax-highlighting (next version will have also code-completion)
* monitor and kill client-processes
* and much more

I have worked with phpMyAdmin before on the web but now have it installed on my laptop along with the Apache Server, MySQL and PHP. I have never used Heidi SQL before so it will be interesting to see what these tools have to offer in terms of working with and manipulating databases.

As I wrote in response to Bo’s comment to my tutorial on working with .sql dump files, phpMyAdmin has been known to fail when importing larger databases, and this is where the command line comes in handy. For some, working from the command line is just preferable to using a GUI. However, not all hosts allow you to have shell access to your account, so it’s a good thing to get accustomed to using both the command line and GUI tools.

One thing about installing phpMyAdmin with PHP5 is that it’s a bit of a chore getting it to talk to MySQL. As I discovered after a lot of head banging, googling, pounding my keyboard, and a swearing, this is primarily a PHP installation problem.

Since v.5 onwards, PHP does not come inbuilt with support for MySQL as a default anymore, therefore if you have trouble connecting to MySQL from phpMyAdmin at your initial installation, chances are that the problem lies in the fact that your PHP is not talking to MySQL. There’s a lot of information in different forums about this, and google is your best friend.

My solution was to delete my manual installation of PHP, and install PHP5 using the msi installer from php.net with its default settings. If you enable all the extensions you will have trouble since some of them require other software to be installed. Your best bet is to install it as it is (selecting your version of the server of course), and then add extensions. You do this by going to “Add/Remove Programs” in Control Panel, choose Change the installation, and enable MySQL, MySQLi, Mcrypt, and Multi-Byte String to run from the hard drive. This step ensures that you don’t need to edit your php.ini file as suggested in many forums, and which you would need to do if you were installing manually. You should also add the extension folder (usually C:/Program Files/PHP/ext) to the PATH. While you are there double check that your installation folder (C:/Program Files/PHP/) is also in the path. Remember that each time you make a change to your PHP install you need to restart your server (Apache in my case) to load the new configuration. And whenever you make changes to your PATH variables, ideally you need to restart your computer for the changes to take effect.

You can test if your PHP install is talking to MySQL by creating and running a PHP file such as the one below, provided kindly to me by Bo.

mysql_connect("localhost", "mysql_username", "mysql_password") or die(mysql_error());
echo "MySQL connection successful.
";
mysql_select_db("mysql_db_name") or die(mysql_error());
echo "Database connection successful.";
?>

(You will need to insert your own values for “mysql_username”, “mysql_password” and “mysql_db_name”).

If your install was successful, you should see something like

MySQL connection successful.
Database connection successful.

After PHP is installed correctly and works with MySQL, you can then install (or run) phpMyAdmin following the instructions given on the web page.

Now that I have finally successfully installed phpMyAdmin, I have all the tools that I need to start doing some serious stuff, and I am going to start writing some code in PHP and also interacting with databases using the three tools that I have at my disposal – phpMyAdmin, Heidi SQL, and the good old command line.

The Next Step – Collecting my tools

So now I have my laptop all set up so that I can write and test php code. My next step was to collect the remaining tools I need to start, so first I had to decide what I’m going to use to write and edit my code. I’ve always liked Notepad for HTML coding because it doesn’t leave behind any codes or stuff. It’s just a plain clean text editor. But the disadvantage with Notepad is that a lot of debuggers will report errors by line number. Notepad doesn’t insert line numbers, and the last thing I want to do is start counting lines of code. So I caved in and decided to find a better editor that’s more suited for programming.

Several options were suggested to me, but I decided to go with two of them for now, because I have commitment issues and like to have options :). My choices are Notepad++ and PHP Designer 2007 Personal, both free. I also have Programmers Notepad that I’ve used before for other stuff, I might try it for PHP too – alternatives are a good thing.

Finally, before getting down and dirty, I need some kind of goal, a project. I learn best when I have something that I am building, so I picked a book that approaches the learning process by creating something. The book is Beginning PHP5, Apache, and MySQL Web Development (Programmer to Programmer), and I’m going to start with that and see if it works for me. I do have some of my own projects in mind, but they’re still wisps of ideas, so I’m going to borrow the author’s projects for now. There are other excellent books out there, but this is one that I grabbed off the shelf at the Free Library.