PHP with MySQL Beyond the Basics

I am proud to announce that PHP with MySQL Beyond the Basics has been released on the lynda.com Online Training Library. It is the sequel to my previous video title, PHP with MySQL Essential Training. It’s almost 11 hours of video training; with the previous title, that makes a total of 21 hours of PHP training!
While the first training was an introduction to PHP and MySQL, in this title I focus on “intermediate PHP” and PHP’s object-oriented features. Objects make it easier to organize and maintain your code, make code modular and reusable, and (most importantly) add clarity by reducing complex interactions to simple behaviors. Once you understand the fundamentals of PHP, you’ll want to learn to harness the power Object-Oriented Programming provides.
PHP with MySQL Beyond the Basics is available online as streaming video to subscribers of the lynda.com Online Training Library ($25/month, $250/year, $375/year with exercise files included). It is will also be available as a CD-ROM soon both through lynda.com and Amazon.com.
Here’s the official description:
In PHP with MySQL Beyond the Basics, expert instructor Kevin Skoglund introduces powerful PHP programming techniques using object-oriented programming (OOP). Both novice and experienced PHP developers will benefit from the efficient, well-organized, reusable, and easy-to-understand code that OOP offers. Kevin shows how OOP techniques can streamline database queries, help manage sessions, and simplify user logins. While building a real-world web application, Kevin also includes practical advice on topics ranging from structuring code to logging user actions. Exercise files accompany the course.
If you are already using PHP but not objects or if you use objects but don’t understand them as well as you’d like, give this training a try and let me know what you think!

March 26th, 2009 at 3:24 pm
Very nice so far. Perhaps I can get an opinion from you.
I’m a desktop programmer - haven’t done much web programming. I want to create/deploy/administer a web site that would certainly use a database.
I’ve gone through your lynda.com Rails tutorials and some Rails books. I’ve also gone over your PHP/MySQL training. I think I can handle either, but I really, really need to pick just one to focus on. And I can’t seem to commit… Rails seems easier to build, but maybe harder to deploy or find a moderately inexpensive host.
Your tutorials have given me two good choices - so how do I pick one to focus on?
March 26th, 2009 at 4:16 pm
@Randy: My recommendation (knowing that plenty of developers will disagree) is to learn PHP/MySQL, then object-oriented PHP, then Ruby, then Rails. Part of what web developers love about Ruby on Rails is that it makes jobs we used to do over and over again in PHP/MySQL easier. But because Rails now “magically” handles a lot of those things for you, it can make it hard to know what it is actually doing for you and why.
Now—can you jump directly into Rails and skip PHP? Absolutely! Especially if you invest the time to learn what Rails is doing for you and why. Just approach it knowing that Rails was built to solve common web problems using best practices and that, if you don’t have experience sorting out those web problems on your own, you’ll either have to educate yourself on them or just trust Rails to do it.
As for easier to build and deploy: PHP is going to require more typing on your part, but it’s not harder. Rails is harder to deploy, but we are talking about a difference of hours, not days.
March 26th, 2009 at 7:35 pm
Just starting chapter 4.
I was doing a couple of small static webpages for the small family companies I worked for, and I wanted to learn programming. I looked into python, but never had the time to do it. Last summer, my father decided he wanted to create a video tutorial site for photoshop, so I decided to look into php. Most of the books I looked at were too front end loaded (with variable variables being in the first chapter for some, which is confusing for newbies), or way too basic.
Then I found your tutorial. The pacing was good, the content thorough, and I learned a lot more in “10″ hours (far more than that actually spent watching it and trying to code up things in my own style), but I grew a lot and learned some important best practices.
I ended up partnering with a friend who did site design in dreamweaver to do some database driven website elements for him, and after the success of that site, they wanted a simple cms. I started out doing it procedurally, and then found a couple of very basic object tutorials out there, but nothing close to what your new videos deal with. I wish I had been able to use this months ago.
I have a simple form class, but I am about to add a DB class, and I am doing great with this as a side project.
To sum up - thanks for really well paced videos that are obviously well thought out and planned, and that cover the salient points while giving room to grow and firm examples of best practices. I look forward to finishing up this course. I just happened to check lynda today after not going to the site for over 6 months, and was ecstatic at the timing.
March 28th, 2009 at 11:16 am
Hi Kevin,
Thank you very very much for the new PHP/MySQL tutorial. I finished the PHP/MySQL traning 8 month back. and I develop various website using that knowledge. Nowadays I’m learning OOP PHP using some eBooks. But I felt very boring. I was looking forward such tutorial form you. Because I love you training flow and the method. I think no one will happy about this release than me. Also these days I’m learning your Ruby on Rails Essential tutorial. While I’m learning I saw some concepts are outdated. - Scaffolding, start_form_tag and so on.
But as I said earlier, I love your flow and the teaching method. No doubt you are my best teacher ever.
Best regards,
Ever loving student
Mohamed Aslam
Sri Lanka
March 29th, 2009 at 12:33 am
Kevin,
Thank you for a wonderful course. It has totally transformed web development for me. This is what I’ve been looking for. After letting Dreamweaver do the dirty work with MySQL and other issues regarding my first site, I totally rewrote it using this course as a guide. As a result, the code is clean, and ultra-maintainable. I look forward to making changes to it now, instead of spending hours looking through generated code I didn’t write.
Cheers!
March 31st, 2009 at 7:45 am
Just finished chapter 9.
One note that I discovered a few months ago that really helped me out: you can do inserts using the {field} = {value} notation also. This makes dynamic queries much easier. You can simply pass an update method a value or not. If there is no value, it makes the sql start with “Insert into {$table} set”, if if there is one, it says “Update {$table} set ” … ” where Id = {$id};”.
I had done up a FormField object that handled every type of Form field (now that I understand inheritance better, these will now be segregated out to child objects). I have a function that goes through the fields, and if the updated value is different than the database value (or there is none), it adds its {field} = {value} to an array that is passed to the database object. If that is empty, there is no need to update the database, so the query does not execute. Otherwise, I can just explode($array, “, “), add it to the above statement, and the query is dynamically created, only updating what needs to be updated.
Just thought I’d share my little trick - seems easier than having to do it two ways.
March 31st, 2009 at 1:37 pm
Hello Kevin. I look forward to diving into this course. I have been waiting a long time for this one…and with you at the helm, it’s gotta be good. Much thanks and appreciation!!
April 6th, 2009 at 9:31 am
Hi kevin, let me start by saying that this is a great video tutorial, it’s clear and relevant. I have been working with php for a while now and I’m slowly moving to objects, and your videos are really helping me, but I had a quick question. What is your reason for for using the mysql_ functions Instead of the new PDO? Which as I understand It, is more OO.
April 6th, 2009 at 10:04 am
Thanks, Anton.
I decided that it was more instructive to learn a more general approach to objects than to lean on PDO’s features. Once you understand objects and how the database functions can be rolled into a class, picking up PDO should be a breeze. In a way, we are learning to create a very primitive PDO of our own.
April 8th, 2009 at 11:42 pm
Hey Kevin,
You have great tutorials. I am really looking forward to getting this on DVD or CD-ROM. Do you have an email list for those that want to be notified when it becomes available, or know of a way to do so via Lynda or Amazon? Thanks.
- George
April 9th, 2009 at 7:30 am
Thanks!
Lynda.com has an email announcement list you can subscribe to: http://www.lynda.com/news/newsletter.aspx
Or you can watch this blog and I’ll announce it here. There is a link in the right column if you want to subscribe to the RSS feed.
April 9th, 2009 at 11:22 am
Anton and Kevin,
Kevin, I really appreciate you using the mysql to “create” your own object. The problem with a lot of general hosts is that they only enable PDO for sqlite, which is the default PHP install behavior. I am trying to convince several hosts to add the driver for MYSQL, but they have not done it yet.
One of the best parts of PDO is the prepared statements, which also exists for mysqli, but is far more finicky (you have to give it an in and out variable), especially for dynamically generated queries.
In the meantime, it is far easier to teach the function based mysql format (esp. since this is a follow-up to the earlier course), and until most hosts catch up, I think Kevin absolutely made the right choice.
April 10th, 2009 at 5:15 am
Hey Kevin,
you have the best tutorials out there, I was waiting to release another tutorial with OOP, and now I’m watching it is here, really appreciate your work, and I’m really happy to start watchin your another tutorial. More of these tutorials Kevin, we all love your stuff!
Thanks in advance!
Best regards,
Tommy
April 16th, 2009 at 5:04 pm
Hey Kevin,
You told me this would be coming out last year and here it is. Awesome, thanks!
May 23rd, 2009 at 12:57 am
Hey Kevin I am looking forward to learning from your tutorials. In the fall I am going into an internship in which I will create an improved website for a fire department. I hope these tutorials will help me develop what i’ll need to make an incredible website!
May 23rd, 2009 at 1:41 pm
Hi Kevin,
I have worked through both your tutorials on PHP at Lynda.com, and I absolutely love them! They have really jump-started my learning of this fascinating language.
Being a near-complete newbie, however, I found myself a bit perplexed by one of the steps in the OOP tutorial. In the User class of the Photo Gallery project, you self-instantiate an object while doing user authentication. What gets returned from the authenticate method is the first element of the $result_array, which I understand is the object reference.
My question is this: How does the object reference end up as the first element in that array of class properties and values? From looking at the instantiate method, it seems as though it is not returning an array at all, but simply an object ($object), while the loop inside the instantiate method simply places values in the class properties.
I know this is something very simple that I am just missing, but I have thought and scoured various help sites for hours trying to figure this thing out with no luck, but I feel like it is key to understanding this project.
Many thanks for your great tutorials!
May 26th, 2009 at 8:35 am
@Mark: the authenticate method calls the find_by_sql method. If you take a look at the find_by_sql method you’ll see that, after retrieving the database results, we have a loop to covert all those returned database rows into objects. Putting the instantiation “high up” in the chain of database interaction means that we always get back objects instead of rows and we never have to explicitly bother with the instantiation.
June 15th, 2009 at 5:09 pm
Hi Kevin
I have just started on Chapter 5 and have already found this series to be an excellent refresher in OOP as well as an enlightening experience into the world of PHP.
I noticed in Chapter 4 that you only use __Constructor() as the name of the constructor for a class, I have never used this before as I usually use the name of the class as the constructor, both work, but I still don’t know which is better!
Thanks again for another great PHP tutorial!
June 15th, 2009 at 5:20 pm
@John: You should always use __contruct(). Using the class name as a constructor is a PHP 4 technique. It still works in PHP 5 but only for backwards compatibility.
June 17th, 2009 at 6:43 am
Hi Kevin,
Thanks a lot for this tutorial. I usually hate video/audio learning and prefer to read, but your tutorials moved at an excellent pace and were highly informative. A quick question: If I were creating an private area for my company’s website to provide files (and possibly stream media) to resellers and others but without public access, would it be ok to start with the framework you created in the photo_gallery site and just modify and build on it for my purposes? I already modified it to display files located outside the public root, (which was pretty easy with the knowledge your tutorial gave me). Or would you recommend using Ruby on Rails now that I have a solid understanding of php/mysql?
June 17th, 2009 at 11:23 am
@Jesse: There are a couple of questions here.
1. Do you have my permission to use the source code?
Yes, as long as you leave in a credit to “Kevin Skoglund, Nova Fabrica and lynda.com” for the initial code.
2. Is the example project technically robust enough?
Yes, but you’ll want to do your own homework on security and handling passwords. You shouldn’t trust my code blindly, and I can’t be liable for it once it is out of my hands and used for another purpose.
3. Should you use PHP or Ruby on Rails?
Both will do the job. It’s only a question of which one you feel more comfortable with, which one your company and coworkers are more comfortable with, and which you will want to work with over the life of the application.
June 20th, 2009 at 7:56 am
Hi Kevin
I just finished Chap 6, so I created some class and sequence diagrams to document my progress, as you mention quite often, there is a lot of complexity to this project, do you use any CASE tools, ER diagrams or UML diagrams? Just wondering as I plan to develop something similar for a college project.
June 20th, 2009 at 11:37 am
@John: I do make diagrams and lots of notes before starting a project. (And anytime I get stuck or puzzled.) Exactly what and how professional depend on the project. Often sketches in a notebook are enough.
I find that putting your plan down on paper, instead of just holding it in your head, exposes any bad assumptions and omissions. It also helps you to break down a large, complex project into manageable pieces.
June 21st, 2009 at 6:17 am
i have watched the tutorial(great work) , but i have to ask, what happens when you have to join multiple tables, when you have many to many relationship..
June 23rd, 2009 at 9:57 am
@ivica: What happens is you have to write more complex code.
If you decide to attempt it, remember there are two parts to the process. 1) Creating the SQL query with the correct joins so you can efficiently query the database. 2) Using the results of the query to instantiate objects. You can also take a look at the ActiveRecord Associations code for Ruby on Rails or Akelos (PHP) to get some ideas.
June 24th, 2009 at 2:14 pm
Hello Kevin, thanks for your great tutorials, Finally I’ve learn the ‘logic’ of OOP!!!!. And I have to thank you for that!!!
Now a question: Do you recommend using prepared statements and MySQLi instead of creating my own Database Class?
I’ve seen very good examples with mysqli, also they say it’s a good way of preventing database injection and all that… but I want your thoughts about it.
Again, Thanks!!!
June 24th, 2009 at 2:25 pm
@Cesar: The two aren’t mutually exclusive. You can create a database class that uses mysqli and prepared statements to interact with the database.
June 24th, 2009 at 3:02 pm
Ok, thank you for your quick response…
Any plans of creating an even more advanced tutorial? I’m thirsty for more.
Thanks!!!
June 29th, 2009 at 9:04 am
Kevin,
Just wanted to let you know how great of a teacher I think you area. I’m a student web designer in my universities library and have been using your Lynda.com videos to learn PHP. They are by far the best thing I’ve come across in my quest to learn web development. I love the approach you take with it. Just thought I would let you know.
July 1st, 2009 at 9:09 am
HI ….
Good post…. I’ve gone through your lynda.com Rails tutorials and some Rails books. I’ve also gone over your PHP/MySQL training. I’ve seen very good examples with mysqli, also they say it’s a good way of preventing database injection and all … Its great I got a Rails tutorial from http://www.macrotesting.com that really helps me to follow you…. thank a lot for your Article ….
cheers
sakthi
July 11th, 2009 at 12:07 pm
Hey Kevin, just wanted to thank you and let you know I reactivated my Lynda account just for this. It’s as great as the first course. Thanks for being thorough and never leaving us hanging on anything.
July 14th, 2009 at 7:59 pm
I would just like to mention that I started this series around the 7th of June and I still cannot get past chapter 8 yet. The first 7 chapters are such a motivation to create OOP based PHP that I cannot stop myself from spinning off in a tangent and creating my own classes and web pages, great inspiration.
August 11th, 2009 at 8:36 am
Hi Kevin,
Thanks for your aweasome videos, I started programming with your first video and now php beyond the basics is incredible! Just what I needed! Are you considering teaching “advanced php”? Please, i’m eager to know.
Best regards,
Pamela.
August 11th, 2009 at 4:34 pm
Thanks, Pamela. I don’t know if we’ll do an Advanced PHP or not. It is definitely something we are considering, but I’ll be recording a few other titles first.
August 13th, 2009 at 10:41 am
Kevin,
Wanted to say thank you for your comprehensive and detailed teaching. Your PHP/MySQL series at Lynda proved to be the most helpful resource I have come across for learning how to build dynamic websites.
There was something in the course that I could never figure out that maybe you could give me a pointer on: You taught on creating an ‘initialize’ php file and defined a few directory constants. You used a directory separator and I believe you were working on a mac. I’m on windows, which I thought would not matter since I was running WAMP. However, whenever I tried making an absolute path like you demonstrated, I got windows DS, and therefore the application broke. It worked as long as I stayed within WAMP’s directory tree. So, if I was building a site locally, how would I test creating absolute paths that I could upload to a webserver?
I hope that makes sense. That was the only part were I got a little lost. Thank you again!
-Talon
August 14th, 2009 at 12:19 pm
@Talon: I believe that’s just the way WAMP works. If you deploy using WAMP, you’ll have the same issue. If you deploy by installing PHP and MySQL on your own or by using a pre-installed version that your web host provides, you shouldn’t experience the same problem.
August 20th, 2009 at 2:10 pm
Hi Kevin!
I hope you are fine as well as your family,
I needed to put these lines on your site telling you that you are the best teacher I have ever seen in my entire life.
Even though I have been learning PHP for long time before I saw your tutorials so installing wamp and all begginers tutorils were too long to watch (for me) BUT the fact is that the jump I made in PHP after watching the whole tutorials is just unbelievable.
I have not yet seen all of your PHP beyond the basics tutorials because I got a little bit overwhelmed with theory on classes BUT I am 100% sure that when I complete it I will make another incredible jump.
I encourage you to do more tutorials on PHP espicially working with frameworks and pick the most suitable one for us so we can improve our skills to get our scripts done in a shorter time and less overwhelming.
Do more for us kevin so we don’t waste our time, effort, and money for not helpful tutorials on the web, please don’t forget us kevin.
I wish you the best in your life kevin as well as your family!
you are such a great teacher and nice person.
take care.
August 23rd, 2009 at 3:45 pm
Hello Kevin,
I just want to say you thanks for the PHP tutorials, especially “Beyond the Basics”.
And Please continue it to the “Advance PHP Tutorials”.
I am waiting for your new PHP Advance tutorials, Please do it again for all of us.
Thanks
and
Take care.
September 8th, 2009 at 8:58 pm
Hello Kevin
Thank you for your great series at Lynda.com
I have been using your videos to learn PHP with MySQL and I am really surprised with the quality and clarity of the lessons. I have spent hundreds of dollars in similar courses and I haven’t learned nearly as much.
Special thanks for helping me to solve some technical issues, I really appreciate it.
Looking forward to learning more with your tutorials.
January 21st, 2010 at 1:16 am
Hi Kevin,
I really enjoyed PHP Beyond the Basics. You made it easy to follow and understand and I agree with everyone that you should continue to add to this library as it is awesome.
I also have a couple of questions…
When a user is trying to access an admin page and gets redirected to login, is there an easy way to keep track of the page they were trying to access and redirect them to that page once they are authenticated (instead of index.php)?
I would love to see the code to update the photographs in the photo_gallery. I tried using a form similar to the upload form and getting the values from the class and setting them in the fields on the form, but how do you handle the file upload? Sometimes the user might want to change the photograph and other times not?
Anyway thanks again for the great courses and I look forward to hearing from you.
January 21st, 2010 at 6:28 pm
Started your PHP Essentials course on lynda.com and discovered an issue you might want to include in the configuration section of the course.
Under Leopard and on systems that have had Snow Leopard installed on top of a previous Leopard install, there is a known issue regarding a 403 Forbidden error that occurs when you enter http://localhost/~username into Safari.
The technical article is at http://support.apple.com/kb/TA25038?viewlocale=en_US
Thanks!
Steve
January 22nd, 2010 at 6:22 pm
Just wanted to drop a very quick ‘thank you’ for this video tutorial set, and your earlier PHP one.
Both are excellent and I’m thoroughly enjoying the second set
Regards,
Johnathan
January 24th, 2010 at 8:46 am
@Tony: 1) Redirect: Before a redirect to a login page, you would store their desired page in a session variable. After login, you would retrieve it, clear the session variable and redirect them to the page they wanted. 2) Update: It is easiest to delete the whole photograph and re-upload it. But if you want to update, the file upload is the same, the only difference is that you need to pull up the exisiting record and update that, rather than create a new record. Everything else is the same.
March 26th, 2010 at 12:16 pm
Just in case anyone was wondering, changing ::self to ::static and using get_called_class() the way Kevin outlined in the last movie of chapter 6, works like a charm in PHP 5.3!