An Ongoing PHP & MySQL Tutorial Thread by JD Walker

JD Walker

Star
Registered
It occurred to me that there are more than a few of you kats on the board with a genuine interest in dynamic web development beyond out the box CMSs and Forums. PHP is the foundation of dynamic web development.

It is also becoming more and more obvious that there are a slew of fraudulent ass clowns disseminating piss poor information about web development, such as writing half assed code, relying soley on GUIs and having you spend money on hacks from India. Janitor type niggas passing themselves off as web authorities. Vegas hookers workin' in Best Buy trying to get you hooked on GUIs. Black ass niggas who thinks building computers makes them experts on all things code.

I have over a decade of web programming under my belt. In this thread I'm not going to take tutorials from other books and post them as if they were mine. We're gonna get code FROM SCRATCH.

Control the source code, control EVERYTHING. Why is it imperative that you rookies know line for line what your code does? You hear the term "Programming Language". It's just that, a LANGUAGE. Imagine going through life not understanding the English language (I believe most of you don't, but that's for another thread). Imagine you had an idea for a story. You can't understand English so you hire an assclown from India to write it for you. How do you know if in fact he's writing your story? How do you know he's using proper grammar? How do you know? You don't. Control your code, CONTROL YOUR IDEA!

If you are one of these algebra flunkin ass niggas, get out of my thread. If you are one of the Colin Powell type niggas, leave my thread. If yousa Best Buy Janitor ass nigga, get out of my thread. If yousa whining ass "it's too hard" type nigga, leave my thread. If you don't understand f(y) = 2xy get out. If you from the south, get outa my thread. If you're a faggot, leave my thread immediately. If yousa bitch nigga, get the fuck outa my thread.

I'm not doing this for the community. I don't give a fuck about the kids nor I don't care about the inner city negroid. There ain't enough Black developers out there, and there is no excuse.

This thread is for kats who are serious. I'm going to cut some years off your learning curve. Now this thread is meant as a SUPPLEMENT to php.net and whatever books you buy. I'm here to break shit down to layman's/real world terms for you to gain a better understanding. That doesn't mean that you are exempt from learning from php.net, that is mandatory. Now while my knowledge of PHP is advanced, there are levels way above advance, so I don't know EVERYTHING about PHP, but I sure as hell know more than enough to put you up on "Markus Frind" type game (look him up).

Through out the day today I'll be covering:
What is PHP
How to Install PHP
How to install MySQL
Procedural vs. OOP
MVC framework
Variables.

Software needed for this ongoing tutorial:
PHP
MySQL
phpmyadmin

An advanced text editor such as Notepadd++, Coda, Textmate, or Dreamweaver.
 
Good shit JD.

For years I've wanted to get more into the LAMP basically saying "Fuck Microsoft," but got lazy as I work for a company that is a Microsoft shop.

I've bookmarked this shit :yes:
 
i'm gonna start my learnin wit ipod/ipad apps and linux but i'm gonna bookmark this for later:ys:
 
I am from the South Shawty.

To quote a word from one of our great southern poets waka flocka, "O Lets Do It"

on the real stepping up the education is always good.
 
What is PHP?

PHP: Hypertext Preprocessor is a widely used, general-purpose scripting language that was originally designed for web development to produce dynamic web pages. For this purpose, PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document. As a general-purpose programming language, PHP code is processed by an interpreter application in command-line mode performing desired operating system operations and producing program output on its standard output channel. It may also function as a graphical application. PHP is available as a processor for most modern web servers and as standalone interpreter on most operating systems and computing platforms.
PHP was originally created by Rasmus Lerdorf in 1995 and has been in continuous development ever since. The main implementation of PHP is now produced by The PHP Group and serves as the de facto standard for PHP as there is no formal specification. PHP is free software released under the PHP License.


Layman's terms
While HTML, Javascript, and Actionscript is processed client side (your web browser) PHP is processed server side. This means that PHP is executed well before it ever hits your browser.

Example:
This is JavaScript!
This is the Header
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus libero sem, cursus in faucibus vel, pulvinar sed elit. Aliquam suscipit quam nunc, eget malesuada erat. Vivamus feugiat pellentesque ante et rutrum. Donec vitae hendrerit mauris. Curabitur lobortis suscipit tellus, sit amet cursus tellus aliquam sit amet. Morbi vitae sem non nisl sodales sagittis. Mauris mattis bibendum mi non sollicitudin. Morbi quis neque libero, in convallis leo. Nunc rutrum convallis porttitor. Mauris a dolor metus, ut pretium nibh. Sed volutpat ornare facilisis. Donec bibendum hendrerit nunc, congue luctus turpis aliquam sit amet.

Home
About
Contact
This is the Footer

Let's look at the source code. To view the source code of an HTML page, simply go to Your Broswer > Veiw > View Source

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>
		<link type="text/css" rel="stylesheet" href="style.css" media="screen" />
		<meta http-equiv="content-type" content="text/html;charset=utf-8" />
		<title>Default Markup</title>
	</head>
	<body>
	
		<script type="text/javascript">
			document.write("This is JavaScript!");
		</script>
		
		<div id="header">This is the Header</div>
		<div id="content">
			<div id="copy">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus libero sem, cursus in faucibus vel, pulvinar sed elit. Aliquam suscipit quam nunc, eget malesuada erat. Vivamus feugiat pellentesque ante et rutrum. Donec vitae hendrerit mauris. Curabitur lobortis suscipit tellus, sit amet cursus tellus aliquam sit amet. Morbi vitae sem non nisl sodales sagittis. Mauris mattis bibendum mi non sollicitudin. Morbi quis neque libero, in convallis leo. Nunc rutrum convallis porttitor. Mauris a dolor metus, ut pretium nibh. Sed volutpat ornare facilisis. Donec bibendum hendrerit nunc, congue luctus turpis aliquam sit amet.</p>
			</div>
			<div id="nav">
				<ul>
					<li>Home</li>
					<li>About</li>
					<li>Contact</li>
				</ul>
			</div>
			<div style="clear: both;"></div>
		</div>
		<div id="footer">This is the Footer</div>
	</body>
</html>

If we look closer we can see the code of the javascript function that's writing "This is Javascript"

Code:
	<body>
	
		<script type="text/javascript">
			document.write("This is JavaScript!");
		</script>
		
		<div id="header">This is the Header</div>



Now let's write a line that says "This is PHP!" in document...

This is PHP!
This is the Header
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus libero sem, cursus in faucibus vel, pulvinar sed elit. Aliquam suscipit quam nunc, eget malesuada erat. Vivamus feugiat pellentesque ante et rutrum. Donec vitae hendrerit mauris. Curabitur lobortis suscipit tellus, sit amet cursus tellus aliquam sit amet. Morbi vitae sem non nisl sodales sagittis. Mauris mattis bibendum mi non sollicitudin. Morbi quis neque libero, in convallis leo. Nunc rutrum convallis porttitor. Mauris a dolor metus, ut pretium nibh. Sed volutpat ornare facilisis. Donec bibendum hendrerit nunc, congue luctus turpis aliquam sit amet.

Home
About
Contact
This is the Footer

Let's look at the source code...
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>
		<link type="text/css" rel="stylesheet" href="style.css" media="screen" />
		<meta http-equiv="content-type" content="text/html;charset=utf-8" />
		<title>Default Markup</title>
	</head>
	<body>This is PHP!
		<div id="header">This is the Header</div>
		<div id="content">
			<div id="copy">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus libero sem, cursus in faucibus vel, pulvinar sed elit. Aliquam suscipit quam nunc, eget malesuada erat. Vivamus feugiat pellentesque ante et rutrum. Donec vitae hendrerit mauris. Curabitur lobortis suscipit tellus, sit amet cursus tellus aliquam sit amet. Morbi vitae sem non nisl sodales sagittis. Mauris mattis bibendum mi non sollicitudin. Morbi quis neque libero, in convallis leo. Nunc rutrum convallis porttitor. Mauris a dolor metus, ut pretium nibh. Sed volutpat ornare facilisis. Donec bibendum hendrerit nunc, congue luctus turpis aliquam sit amet.</p>
			</div>
			<div id="nav">
				<ul>
					<li>Home</li>
					<li>About</li>
					<li>Contact</li>
				</ul>
			</div>
			<div style="clear: both;"></div>
		</div>
		<div id="footer">This is the Footer</div>
	</body>
</html>

At first glance, it looks like it was just randomly written there. But let's take a look at the PHP code used to print "This is PHP"...

PHP:
<body>';
	
		echo 'This is PHP!';
	
		echo'
		<div id="header">This is the Header</div>

What your View Source didn't show you was me terminating at the body tag, using the language construct "echo" to print "This is PHP" and resuming the HTML. All this was processed on the server long before it hit your browser. The advantages of server side execution is 1) SECURITY and 2) CONTROL.

Javascript controls your browser. It listens for event handlers and executes whatever functions the programmers wants to run on those event handlers i.e. games and whatnot.

PHP controls the output of the pages themselves. The programmer has the control to show you what he/she wants you to see.

While these are 2 separate and distinct languages, they can be combined to form AJAX. You can do lots of cool things with AJAX, which will be covered much later in this ongoing tutorial.
 
You ninjas better take note. If you want to get your web development skills up PHP is easy to learn and you can set up an environment locally. Pay attention to the knowledge about to be dropped here.
 
What is MySQL?

MySQL is a relational database management system (RDBMS) that runs as a server providing multi-user access to a number of databases. MySQL is officially pronounced /maɪˌɛskjuːˈɛl/ ("My S-Q-L"), but is often pronounced /maɪsiːˈkwɛl/ ("Micey Quell") or /maɪˈsiːkwəl/ ("My Sequel").[citation needed] It is named for original developer Michael Widenius's daughter My.
The MySQL development project has made its source code available under the terms of the GNU General Public License, as well as under a variety of proprietary agreements. MySQL is owned and sponsored by a single for-profit firm, the Swedish company MySQL AB, now owned by Oracle Corporation.
Members of the MySQL community have created several forks such as Drizzle and MariaDB. Both forks were in progress long before the Oracle acquisition (Drizzle was announced 8 months before the Sun acquisition).
Free-software projects that require a full-featured database management system often use MySQL. Such projects include (for example) WordPress, phpBB, Drupal and other software built on the LAMP software stack. MySQL is also used in many high-profile, large-scale World Wide Web products including Wikipedia, Google and Facebook.


Basic usage with PHP to query the MySQL and return results:

PHP:
	$query = "SELECT * FROM table";
	$result = mysql_query($query) or die(mysql_error());
	
        while ($row = mysql_fetch_array($result)) 
	{
	   $foo[] = array(
		'name' => $row['name'],
		'email' => $row['email'],
		);
	}


This here is the MySQL query language:
Code:
   SELECT * FROM table

PHP uses built in functions (command line) to access the Database. While PHP and MySQL both work seamlessly together, do not forget that these are 2 separate languages.
 
This is a dope ass post, I'm hoping you go further with it and hopefully post some tutorials. I am trying to get my shit tight!
 
How different is SQL and MySQL .........I took SQL for one of my programming classes the teacher I had didnt know what he was doing :smh::smh::smh::smh:
 
What is MySQL?

MySQL is a relational database management system

Basic usage with PHP to query the MySQL and return results:

PHP:
	$query = "SELECT * FROM table";
	$result = mysql_query($query) or die(mysql_error());
	
        while ($row = mysql_fetch_array($result)) 
	{
	   $foo[] = array(
		'name' => $row['name'],
		'email' => $row['email'],
		);
	}

damn dude can you break this code down in laymans term?

I am confused here with this one.
 
It is also becoming more and more obvious that there are a slew of fraudulent ass clowns disseminating piss poor information about web development, such as writing half assed code, relying soley on GUIs and having you spend money on hacks from India. Janitor type niggas passing themselves off as web authorities. Vegas hookers workin' in Best Buy trying to get you hooked on GUIs. Black ass niggas who thinks building computers makes them experts on all things code.

If you are one of these algebra flunkin ass niggas, get out of my thread. If you are one of the Colin Powell type niggas, leave my thread. If yousa Best Buy Janitor ass nigga, get out of my thread. If yousa whining ass "it's too hard" type nigga, leave my thread. If you don't understand f(y) = 2xy get out. If you from the south, get outa my thread. If you're a faggot, leave my thread immediately. If yousa bitch nigga, get the fuck outa my thread.
*dying*

:lol: :lol:

Comedy aside, props on dropping that info JD. Much respect on that man. Now let me get my Calculus D+ gettin ass outa your thread.
 
Installing PHP on Mac

OS X has Apache and PHP installed by default. However chances are that that copy will be dated. In that event you want to head over to Marc Lynage's site http://www.entropy.ch/software/macosx/php/ and download an updated version of PHP. Follow the step by step installation, it's fairly painless.

PHP runs locally in your /~user/Sites folder.

If you want to make sure PHP is running after the install, place a "test.php" script in your /~user/Sites folder and copy and paste the following inside:

PHP:
<?php
   
   echo phpinfo();

?>

Go to the Systems Preferences > Sharing > check "Web Sharing" This is start up Apache and PHP.

Next in Safari/Firefox/Chrome enter the following:
http://127.0.0.1/your_user_account_name/test.php

What you should see is a long list of settings and modules. if you don't, and all you see is:

Code:
<?php
   
   echo phpinfo();

?>

Your installation failed.



Installing MySQL on Mac

Download the latest STABLE build of MySQL here:
http://dev.mysql.com/downloads/mysql/

This is a pretty easy install. After you install however you must set up an admin account in MySQL. To do that, go to you Applications > Utilities folder and fire up the "Terminal" type the following:
Code:
/usr/local/mysql/bin/mysqladmin -u root password new_password_here

relaunch Apache, and your ready to go!



Installing phpMyAdmin on Mac

What is phpMyAdmin?
phpMyAdmin is a free software tool written in PHP intended to handle the administration of MySQL over the World Wide Web. phpMyAdmin supports a wide range of operations with MySQL. The most frequently used operations are supported by the user interface (managing databases, tables, fields, relations, indexes, users, permissions, etc), while you still have the ability to directly execute any SQL statement.

1. Go to http://www.phpmyadmin.net/home_page/downloads.php and download the archive.

2. Unzip the archive and place the resulting folder in side your /user/Sites folder.

3. Rename the phpMyAdmin folder to something easier to read

4. Read the directions, and enter the approroate values in the configuration file

5. The url to access phpMyAdmin will be http://127.0.0.1/your_user_account/Sites/phpMyAdmin_folder
 
Installing PHP, MySQL, and phpMyAdmin on Linux and Windows

I don't know how to do either.

I'm assuming "LAMP" applies to Linux OS by default?

If there are any of you who have successfully installed and run PHP, MySQL, and phpMyAdmin on both these platforms it would be appreciated if you can offer a step to step installation guide like the one I provided for the Mac.
 
Procedural programming vs. OOP (Object Oriented Programming)

This is an argument that is as heated as Mac vs. PC, Canon vs. Nikon, etc.

Here are 2 videos and a link explaining the differences between the 2...




Before I begin, I will say I don't have "loyalty" to neither, however 90% of the time I'm coding procedural. Now I'll break it down in layman's terms...


Basic Procedural approach:
PHP:
<?php 

   echo "Wazzup BGOL."; 

?>

Basic OOP approach:
PHP:
<?php 

class helloWorld { 
  function myPrint() { 
    echo "Wazzup BGOL."; 
  } 
} 
$myHelloWorld = new helloWorld(); 
$myHelloWorld->myPrint(); 

?>


They both do the same thing. I know there are some Java programmers on the board so the latter example looks very familiar. When coding desktop/phone applications, you certainly must use the OOP approach. However, OOP doesn't translate very well on the web in a heavy traffic environment. The web is inherently procedural. By default OOP will cause about 15-20% overhead to your web application if you decided to use OOP for most of your web application. Java developers looking to branch in to PHP need to understand that instead of ONE person using their application, Hundreds if not thousands will be using their web application concurrently. There's no way I could justify telling you to use the latter example instead of the prior to print out a simple string. The knock against procedural programming is a legit one, if you don't watch it your code will get messy real quick, however if you are skilled the procedural approach can be just as clean as OOP.

Analogy:
2 cars are racing. Both cars have over 300 horses under the hood. Both cars are powerful.

The 1st car is a heavily modified rice burner that has won a lot of races. The driver pops the hood. You see the engine, but you can't make sense of his modifications. It would take you days to figure out what he's done to the car if you had to work on it, but that doesn't matter to him because he wins his races.

The 2nd car is an old school Cadillac Eldorado. Sweet comfy ride, lots of power, when you pop the hood everything is where it's suppose to be. However that driver isn't winning anything anytime soon. While the Cadillac is well built, it's a gas guzzler and performs poorly.


Both cars have their place on the road just as procedural and OOP have their places.

If you want a real life example of the Cadillac look no further than the board you are posting on right here. vBullettin is heavily OOP. I'm assuming there are at least 1000 people browsing this forum at any given moment? I see the complaints about performance. The HNIC will have no choice but to upgrade hardware.



When to use procedural
If I'm designing a site that has to potential for high traffic then I use the procedural approach.

When to use OOP
If you are developing APIs then I really don't see any other way but the OOP approach. I use the phpMailer API all the time, it works great and it's a great example of how to put together an web based API.

For the OOPers out there, during this tutorial I will try to create OOP alternatives to examples when possible.
 
Model–View–Controller (MVC)

This is the programming architecture I use religiously and I will be using it over the course of the tutorial. MVC is what keeps your code clean.


Model: The model controls the state of the web application. For example, this forum. When you make a new post, a set of routines and queries are made by the model to change the state of the application and to stand ready for new commands

View: It's the template/skin user interface used to display content. The View does nothing but that.

Controller: The controller sends command from the View to the Model and vice vera. When you perform a search the controller sends that command to the model and the model computes the requests, sends the results of the requests back to the controller and the controller changes the state and the View to return your search results.
 
saIULQ9k.jpeg


http://rapidshare.com/files/191462423/Teach_Yourself_PHP_in_24_Hours.zip
 
Back
Top