Tutorial: PHP + MySQL (part 1)

Hello, chums! Forgive the plural. I feel presumptuous enough talking as if I had an audience most the time, it must be even more so to suggest that that audience is of a greater number than one! Though, I do happen to believe that at least one person will be reading this because I plan to enforce that he do so via completely non-coercive means.

So, tutorial time. Disclaimer: I was not taught PHP (or MySQL, which is typically used, and herein will be taught, in conjunction with PHP). My knowledge of each has been gleaned from tutorials, documentation, trial-and-error guesswork, and at times, I don’t doubt, sheer assumption. This tutorial aims to show how it is that I have produced a working website (not this one, though) using that fragmented but practical knowledge. Ok, that’s the disclaimer out the way, let us get to the learning. It’s what we’re all here for, yes? Yes.

PHP stands for ‘PHP Hypertext Preprocessor’. A recursive acronym, no way? Yes way, and pretty neat! It is a programming language of sorts. Not quite the same as C or Java or Python which are proper and none of which I know, two facts which correlate and probably have a causal link too. PHP runs on a server – the user-interface being browser-based. A Linux server, Apache in the case of the package I’m running. So when it’s installed you run ‘Apache’ and it all works (ok not really but we’ll get to specifics later). The process as I understand it, is vaguely thus: 1) you write the PHP code; 2) via your web-browser, you elect to request the PHP code; 3) the Apache server-environment intercepts that request, or else is given it by the Operating System, and uses its various rules to ‘parse’ the code and return it to the browser. That which is returned to the browser can be a host of things: commonly an HTML page, but also can be a generated image, or I would guess other things which, having not needed to know, I have not endeavoured to learn.

Setup. You can’t just open notepad, write PHP, open it in Chrome (or one of the inferior browsers) and get results. I’ve tried. It was disappointing so don’t try it. Chances are, if you’ve had to resort to this tutorial, you’re running a Windows computer, or maybe Mac (no offence, this is all just statistics). Probably not one of the other ones which I should learn to use one day, I have no idea how I would develop PHP code on those machines. But yeah, I have Windows Vista. Now, the thing to do next is to install some piece of software that parses the PHP for you. I’m running a package called ‘XAMPP’ which stands for cross-platform Apache MySQL PHP Perl. Which all work together. There are others available but this one works great. Install a version for your computer (http://apachefriends.org/en/xampp.html) , unpack it if it’s a .zip file, run it if it’s an .exe file. You’ll need to create a whole new ‘drive’, a new top-level directory type thing for it to work, and I did that by partitioning my C:/ drive. I ended up with my original drive and a new one, Z:/. That was rad. There are loads of tutorials, but loads of ways in which you could get stuck, so google’s a better bet than me putting a link here. Also I lost the link that helped me when I got stuck sorry guys, but to be honest I think you’ll be ok. This is like small fruit compared to the big fruit coming up next.

Ok go away while you set that up.

Ok hi again! Have you changed your hair? It looks much better. Ok, so anyway. Assume you’re now running XAMPP, you probs are. There’s a little control panel box that lists Apache and MySQL amongst other things, once you set both of these running, you’re set! Now, simply save a valid PHP file (example.php) in Z:/xampp/htdocs/ folder, where ‘Z’ is the partition, and view it by pointing your browser to (http://localhost/example.php) : simple! BUT!

But not so simple, right? Yeah, the problem here is that you don’t know how to write a valid PHP file. Not to fret, I got it covered! New paragraph going on here because setup is complete, in my eyes. Setup over with, now on to coding! Ok but to code effectively you need to know how to code, and to learn how to code, fasten your seatbelt and prepare to ride the learning train; destination: knowledge. To learn how to code you need to know the language you’re writing right? Wrong! Do what I did. It’s easier. I copied someone else’s PHP code, ran it, and then studied it and guessed at what did what, then played with it, ran it again, and added stuff. I can’t go through what I did because I can’t remember! It’s a fun process of discovery.

Ok shit I just remmebered you guys don’t even know HTML. Shit shit shit.

Ok forget all that. To code in PHP you need to know HT-FRIGGING-ML. Jesus. Ok shit I’m getting a bit jumpy here writing this is way more stressful than I thought it would be, I just realised I’m jumping several guns. Sorry about the swearing. PHP is about customising HTML pages. Web pages. Ok fuck this. There’s so much you don’t know. Ok tutorial over I’ll continue soon. Take a breather.


This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s