Close

php

The 80/20 rule of web development

I once did this YouTube video.

It was called the “Exact PHP Skills You Need to Learn to Get Paid to Code.” The idea was there’s all these things you think you need to learn or you get told by some ranting know-it-all that you need to learn…

But, in reality…

You only use a small fraction of those skills on a regular basis.

So, I made a list of the things you’ll use most often as a PHP developer.

The things that make up 90% of the coding I do.

Variables, arrays, loops…

That sort of thing.

It’s been funny to watch the comments over the years. Predictably, a hoard of know-it-alls have chimed in with their “but, but”. “You need to learn OOP and form security and Laravel…”

It always turns into this massive “wish list”.

And sure… learn those things.

But, that wasn’t the point.

The point is… what’s the absolute bare minimum to get started?

Because, the reality is with any language or technical skill, there’s a 20% of all the skills you could learn that you’ll actually use 80% of the time in your work. So, why learn some random thing you’ll use twice a year… when you’re starting?

And ignore or spend less time on something you’ll use over and over again?

You shouldn’t.

Of course, the trick is figuring out that 20%.

Which was the point of the video.

Thankfully, most people get it.

I’ve had probably 10 times as many positive comments like this:

“I’ve been coding for two years, read almost every book you could read cover to cover. I knew the languages and even how to use them, but I felt as if I had to be perfect and and that I needed to remember every tag, property and function to be considered a professional. I was anxious that my skills were not up to par, but listening to your podcast had helped me realize I have the skills to be professional web developer. Thanks man.”

Which was the entire point.

To free you up from that “perfection trap”.

Thinking you need to learn 1000 things before you can get hired.

You don’t.

In any case, I think that’s why my students tend to have success coming out of my PHP course. Because, I teach them the things that they’ll actually use in their jobs, not 1000 obscure things they’ll use once or twice…

But, that make me look smart.

I don’t care about me.

It’s YOU that matters.

Anyway, if you wanna take my PHP course, you can get access to it for nothing over on Skillshare. And yes… when you’re done with it, you can jump into my PHP OOP course and the other advanced PHP courses I have, as well.

They’re all over there.

And, you can access them all for free.

Link for all the details on how is here: https://www.johnmorrisonline.com/skillshare

Later,

John

March 21, 2019

Object-oriented programming in PHP

This just can get confusing as hell, sometimes.

I kinda just shake my head at the “Intro to OOP” tutorials that spend the whole time talking about “polymorphism” and “encapsulation”. It’s no wonder a lot of developers hold out learning OOP.

Anyway, the most important…

Most fundamental…

Object-oriented programming principle is much, much simpler.

And, I think a big “aha” for developers.

Of course, that’s probably just my naive “don’t confused the hell out of people on day 1” opinion, but who knows. Anyway, if you’ve been wanting to tackle OOP in PHP, but been afraid it’s complicated as hell…

Give this video a watch:

I think you’ll see… it’s a lot simpler than you think.

(And, most coding instructors make it out to be.)

If you do, I’d appreciate it if you’d share it with anyone you know who is also looking to learn object-oriented programming.

Later,

John

November 5, 2018

Why so many programmers say PHP stinks

I was perusing Quora today and came across this question:

“Why do so many programmers say PHP is a bad language?”

Of course, that ruffled ol’ Johnny’s jimmies, so I clicked to so see some of the answers and this one made me laugh:

“They’re the same people that want to ban bread knives from being sold based on the premise that they’re murder weapons.

“As the saying goes – ‘PHP is so easy to learn that any idiot can use it. Far too many do.’ You can write terrible, horrible code in every programming language out there. In hard to learn higher level languages like C++, your program will crash or simply not work. In PHP, it will mostly work and allow you to hack along until it does.

“Before PHP5 it was definitely a bad language. PHP5 cleaned up most of the really bad stuff. PHP7 fixed some more fundamental issues, and is really honestly a good mature development environment. For legacy B/C reasons a lot of weird shit is still around, like the infamous string type juggling (1+”1e2f” equals 101…), but trying so actually gives notices these days and is on the way to official deprecation.

“If you use a professional, mature and high quality framework like Symfony you’ll be surprised at the elegant, powerful, clean and highly performant code you can write in PHP that will pass every single software engineering quality test you can think of.”

I mean, look.

Do you blame the wrench if a car is built like s!@#?

The hammer, if a house falls apart in a year?

The gun, if a psychopath shoots up– oh wait…

Point is, PHP is a tool… just like any other language. A screwdriver, a hammer a wrench. Which one you use depends on the job. And anyone who thinks PHP is a double-clawed hammer… is the moron, IMO.

Trick is… knowing how to use the tool properly.

(That’s what sh— dammit, there I go again.)

The truth on all this language war stuff…

Is PHP7 officially put this all to bed.

It’s a mature language, at this point.

All the naysayers are just crying at ghosts at this point.

Anyway, if you want go beyond the “script kiddie” stuff and learn how to build mature, professional PHP applications that will allow you to write your own check when it comes to your web development career…

My PHP curriculum on SkillShare can help you get there:

And, you can get access for nothing. Deets at the links above.

If you wanna make PHP your thing, that’s how to do it, IMHO.

Now, it’s just up to you to grind it out.

Later,

John

September 24, 2018

What they DON’T tell you about PHP

I got this Facebook comment from Jeremy:

But, you won’t hear that from any PHP hater.

And, I know…

I’m beating this horse to a bloody pulp…

But, it’s like I said yesterday:

And, people asking if it’s true.

So, bust out the baseball bat…

I’mma keep hammering away at this.

In any case, you can sit around worrying about if “PHP is dying” or whatever nonsense they dream up next… or you can make like Jeremy…

And, get to work.

There absolutely ARE plenty of tech jobs…

And, freelance projects for PHP developers.

Just gotta get out there and get after it.

Anyway, if you need to learn the PHP skills to get these jobs and/or clients, I’ve got over 20 hours of PHP training you can get access to for nothing.

It’s all over on SkillShare.

Details on the no-cost access is here: https://www.skillshare.com/r/user/johnmorris

Later,

John

August 31, 2018

PHP usage statistics are bunk

Blah, blah… traffic… something, something. I guess that’s the strategy. When usage statistics don’t show that PHP “is like totally dying and stuff”, then we jump to whatever other statistic that fits our narrative. Anyway, here’s the rebuttal:

August 24, 2018

PHP isn’t used by REAL websites

I’ve been getting these comments more and more lately:

“…let’s just consider that 80% figure, in those stats all websites count the same, so 1 WordPress blog that has not updated in 10 years and gets 10 hits a week counts the same as Youtube getting billions of hits, you see the problem with that, in reality when measured by what counts (usage/traffic) most of the web is not powered by PHP”

This seems to be the new thing among PHP haters.

They really want to be able to say PHP is dead. But, then there’s those pesky usage statistics showing it’s used on 80%+ of websites.

“Well, well, but, but…

“It’s all about the traffic… duh!”

I mean, nevermind Slack or Etsy or Flickr. I’ll even leave out Facebook and Wikipedia. We’ll forget WordPress and Drupal (Whitehouse.gov, NCAA.com, Tesla).

Nope, we’ll just conveniently ignore all those…

And, just go straight to how stupid this argument is.

Think about it this way.

The niche I freelanced in I was building membership sites using WordPress. And, I once built a membership site for a famous blogger named Michael Hyatt.

That site grew to have several thousand members.

All paying 30/month to be members.

Eventually, it became a 7-figure site.

He had a staff of around 10 or so people.

And, they paid me between 30-40K in the time I worked with them on the site. But, because it was a membership site that released content once a week.

It might get a few hundred visitors a day.

It wasn’t a massively trafficked website.

So, the f!@# what?

Did that make their muney less green?

Does that not count as a “real” site?

Point is…

Judging a site based solely on the amount of traffic it gets is an incredibly dumb way of assessing its potential to employ you.

Lots of uber low traffic websites make bank.

And, employ lots of people.

And, pay really well.

The fact of the matter is PHP is used by really high traffic websites, it’s usage statistics are much higher than any other server-side language.

And, it has gotten dramatically better in PHP7.

So, it ain’t goin’ nowhere, Pancho.

No matter how loudly you shriek about it.

End of story.

Anyway, if you’re not one of these PHP-hating scrubs and wanna learn PHP and scoop up all the jobs out there, I’ve got over 20 hours of PHP training you can dig into.

Link is here: https://skl.sh/2JhEqT0

That’ll give you an exclusive 2-month no-cost trial of SkillShare. You’ll get FULL access to my entire library of courses. Take all the training you want.

Cancel any time before the 2 months is up…

And, never pay a penny.

Not a bad gig.

But, up to you… Pancho.

Link again is: https://skl.sh/2JhEqT0

Later,

John

August 23, 2018

Fake PHP jobs

So, from yesterday…

There’s obviously lots of PHP jobs posted out there.

But, Leon asked this in response to that video:

“How many companies lie about their intentions to hire, to create a false shortage, to argue for more (cheaper) foreign workers?”

I’ll keep it real.

My gut reaction is:

“Who gives a f!@#?”

It’s not ALL of them. I know that. And the only way you’ll really know is to apply. It just feels like an excuse to me. And, that gets my inner grumpy old man outta his chair.

Buuuuuuut.

Let me be civil.

I looked it up. I can’t find any hard numbers on it. I saw one guy said 87%, but didn’t provide a single shred of evidence to back up his claim.

And, that seems like a ridiculous number to me.

So, don’t fall for any numbers anyone might spout off.

Unless they give you some real evidence for it.

But, there’s a really simple way you can tell if a job is fake or not. It’s called their “employment brand”. Think of something like Glassdoor.

Is the company reviewed there?

Or, does it have reviews on Indeed?

Does it have a “what it’s like to work here” on its site?

A company’s employment brand is content, both on and off its own site, that talk about what it’s like to work there, what job openings they have, how to apply…

All that.

If it does, it’s probably legit.

If not, probably not.

And when you find a job posting on one of the 10 different sites I showed you in the video, yesterday, you can take about 5 seconds and google a company before applying.

It’s that easy.

So, don’t let this be an excuse.

If you’re legit worried about it…

Search on Glassdoor, then.

Filter by a company’s star-rating.

And, take 2 seconds a google each company…

Before you take the time to apply.

So, noooow… with that excu– ahem reeeason put firmly to bed, now what’s stopping you from applying to a bunch of PHP jobs, today?

Not ready yet?

Need to shore up your PHP skills?

That’s what my PHP curriculum on SkillShare is for. Over 20 hours of PHP training — beginner to advanced, MySQL, OOP, sessions, cookies, etc, etc.

Link to get started for nothing is here: https://skl.sh/2JhEqT0

Later,

John

August 18, 2018

PHP jobs you can apply for right now

I get a lot of PHP haters who love to drone on about there being no PHP work out there. Or, well-meaning PHP developers who are struggling a bit to find PHP work. Well, this massive list of PHP jobs should cure both:

And, do let me know once you get hired. Gives me ammo for the PHP haters. 🙂

Later,

John

August 17, 2018

Why is PHP still being used to create websites?

This was pretty epic.

A real drop-the-mic-er.

It was this answer on Quora I saw the other day from Vakrokh. The question was:

“Why is PHP still being used to create new websites? Why aren’t all new sites using more modern frameworks such as Django or Rails.”

I love how these guys just throw “modern” in there.

As if “modern” automatically equals “better”.

Anyway, here was Vahrokh’s answer:

“PHP is not still being used. ‘Still’ is a word suitable to 2012 PHP, when it has been under an heavy rework and to end users / programmers it looked like it was being neglected and forgotten.

Since 2014 we have PHP 7 (currently, PHP 7.2). PHP 7+ has a massive number of modern features that easily put it on par with Python / Ruby if not above. Interfaces, closures, traits, iterators, containers, exceptions, async programming, websockets (and much more) put PHP back in the competition.

Modern PHP frameworks (Laravel being the most famous, but there are dozens) easily compete with other languages.

Furthermore, PHP 7 brought in something that missed in PHP 5.x: speed and low memory consumption. PHP 7 speed is 100% faster than PHP 5.x and PHP 7.2 is 105% faster than PHP 5.x. The same web request that takes 80 MB RAM on PHP 5.x, takes about 7 MB RAM on PHP 7.2.

A massive saving!

PHP 7 even beats Facebook’s ‘native compiler’ in several tasks. This translates into reduced hosting and upgrade costs. We are talking about the language that could be hosted the cheapest of all, now getting cheaper.

I won’t cover PHP MVC frameworks because there’s copious literature about them. Let’s say there is a flavour for everyone: from the fully featured Laravel and Symfony (that easily compete with Django and Ruby On Rails) to API / backend optimized frameworks, to ‘beginners frameworks’ and mini / micro frameworks.

Last but not least, you can find and hire PHP developer everywhere and their wages are competitive.

All of the above, show how and why PHP is still a widely common choice for new projects.”

Boom!

And, here’s the other thing. In this tornado of new stuff coming out all the time, PHP has been a kind of calm at the center of that storm.

Steadily moving along.

Making the necessary adaptations.

And, still powering 80%+ of the web.

Plenty of work to be had.

(Unless you’re a blue-haired, latte-sipper who “like, OMG, has to work in NYC or L.A. for like a rad start-up. And, PHP is like… ugh… dirty. Gah!”)

If all that chaos has you overwhelmed and terrified of the future, you can simply and calmly just step out of it. PHP is one great way to do that.

That and learning programming principles…

Beyond the languages.

Like object-oriented programming.

Design patterns like MVC.

Security.

Hell, even something simple like proper form-building.

That’s the stuff to learn. The “eye” at the center of a constantly-changing industry that can give you some peace of mind, security and some confidence.

Anyway, let me not blabbeth longer.

Fist bump for Vahrokh.

And, if you want to learn those core languages and programming principles, then check out my PHP curriculum on SkillShare. Everything I mentioned above is in there for the taking.

Link is here: https://www.skillshare.com/r/user/johnmorris

Later,

John

August 7, 2018

All the web development you’ve learned will be obsolete in a year

You ever watch the movie, Twister?

There’s a scene at the end where they’re trapped in this small shed, tied to some pipes as a Tornado rolls right over them, tearing the shed to pieces.

Debris everywhere.

Legs flying in the air.

Complete chaos.

But, there’s a moment where, Helen Hunt, one of the main characters, can see all the way to the top of the tornado. And, it’s nice calm, blue sky.

Almost peaceful.

That’s sometimes how I feel.

As I’ve talked about… all the chaos and change coming so rapidly in our industry. There’s so much to learn and so little time to learn it.

Have I learned enough?

Won’t it all be obsolete in a year, anyway?

How do I keep up?

It can feel like a tornado swirling around you.

But, there is a way to find the “eye” of that storm. The calm, almost peaceful place where you feel confident, secure and excited.

Tom on Quora said it perfectly:

“[Web development] is difficult, sure, and the technology is an always moving target as the frameworks change so rapidly. But fundamentals of design and engineering don’t change. So I didn’t have anything to fear regarding that, it was a matter of learning how to apply those using the flavor of the day.”

It’s easy to get caught in the chaos…

When you focus too much on the “flavor of the day”.

The latest “ermagerd” framework.

Or, shiny, new language.

And, you believe the Medium-heads that say you “have to learn every single one or you’re like a total noob and will never get any work”… blah, blah, blah.

No.

Focus on fundamentals.

And, you’ll be fine.

Another thing that’s true, but unpopular to say, is that despite all dire predictions to the contrary, the core stack for a web developer hasn’t changed much.

The most used languages for websites are still:

HTML, CSS, JavaScript, PHP and MySQL.

I know… BLASPHEMY!

But, it’s just statistical fact.

All these new languages and frameworks are great.

Node, Angular, React, Go, etc.

In fact, do learn them, at some point.

But, the majority of websites still run plain, old, vanilla, boring (read: calm and peaceful) HTML, CSS, JS, PHP and MySQL.

So, learn those first.

And, frankly, if you’d just stuck with those all this time…

The chaos wouldn’t really have bothered you much.

In any case, do what you want. I’m gonna sit over here in the blue sky, sippin’ my rum and coke… taking all the work the Mediums-heads are “too good” for.

If you wanna chase tornadoes, it’s all yours.

Of course, if you are like me, then my coding curriculum is exactly what you need to learn that core stack. PHP, MySQL, OOP, HTML, CSS, JS… it’s all in there.

And, you can get started for nothing.

All the deets on that are here: https://www.skillshare.com/r/user/johnmorris

Later,

John

August 6, 2018

Learn PHP In 30 Minutes

Be honest.

What was your immediate thought?

Hopefully, it was “Yeah right!”

I was cruising through the PHP groups I’m in this morning and I ran across someone pimping this. I clicked to see exactly what it was. And, it’s an ad for the “PHP Crash Course”.

3,317 students enrolled (supposedly).

Sigh.

I mean, who knows?

Could be a great course.

But, c’mon.

It’s a completely wrong-headed approach.

Today, I also got asked this question on Quora:

“How much time would it take to learn web development from scratch and start making some [muney] from it as a freelancer?”

Sigh (x2).

Can we stop with all this?

I mean, I get it. These are people that are probably working some job they hate or just about to graduate from college… and they want to get into a dev job fast. They can’t stand another day where they’re at now.

Or, are terrified of dropping 100Gs on a college degree…

Only to wind up at asking “Would you like fries with that?”

But, it’s NOT about speed.

To me, the bigger question is…

“Can you get hired for that freelance gig and actually deliver?”

Or…

“Can you get that tech job and actually perform?”

Cuz, you could learn PHP in 2 nano-seconds and get a job or a freelance gig… but if you build things that suck… you’ll be OUT of that job or gig in about 2 nano-seconds, as well.

I think you get it, though.

I know you’re smarter than this.

But, I also know this stuff can be tempting in your moments of weakness.

Just remember.

“Nothing worth having comes easy”. 

Anyhoo, if you want a real PHP curriclum, you can get started with mine for nothing over on SkillShare. Here’s what’s in there:

It’s about 19 hours of hard-core PHP training.

And, I dare say, you’ll learn more about PHP than most developers ever will. But, that’s my totally biased (and usually right) opinion. In any case, you can go here to start your 2-month, no-cost trial: https://www.skillshare.com/r/user/johnmorris.

Take all those courses (and all my others).

Cancel anytime before the 2 months is up.

And, never pay a quarter.

If you’re looking to “learn PHP in 30 minutes”… then, this isn’t for you. But, if you’re ready to roll up your sleeves, put in the work and spend the next few months grinding…

I believe you can master PHP in that time.

And, gain the confidence to KNOW…

That you can deliver when you do get hired.

And, to me, that’s worth a helluva lot more than some flash in the pan “crash course”. Buuuuut… to each their own.

Link is here if you want to roll with me: https://www.skillshare.com/r/user/johnmorris

Later,

John

July 11, 2018

Plain PHP Is Completely Useless

I saw this comment in a Facebook group I’m in:

“I spent more than a year on learning and excelling in core php… But as I entered in job market… It’s useless… Completely useless…. Invest your time in php frameworks. And yes we can’t learn frameworks without learning basics”

First off, I feel this.

When I started, it took over 4 years to learn “core PHP”. I know, I’m an idiot, but things were a lot different back then. Anyway, by the time I learned it, all these frameworks like CodeIgniter and Laravel…

And, applications like WordPress and Drupal…

And, Slim PHP…

All these new things had grown up around me.

And, I felt like, “Aaaaaaaaaaah! Now I gotta learn all this s!@#, too!”

It’s frustrating.

But, here’s the deal.

In my opinion, the PHP path is this:

  1. Core PHP
  2. Object-Oriented Programming
  3. PHP framework (or application).

So, yours truly, for example. I obviously know core PHP and OOP in PHP. And, my “framework” (application really) is WordPress. Once you have that down, you’re pretty much set when it comes to PHP.

But, the big thing to remember is…

You don’t need to learn EVERY framework.

Or every application.

Just pick one and specialize in that.

Another thing… remember the job market is vast, diverse and regional. In some areas, it’ll be all Laravel. In others, CodeIgniter. In others, yet… it’s WordPress. If you freelance it’s core PHP and WordPress.

It just depends what YOU wanna do.

Finally, this is why I believe it’s so important to learn core PHP as quickly and as deeply, as possible. Because when you do, learning OOP and then a framework or application is a helluva lot easier.

And, I think this is where a lot of developers get stuck.

And where a lot of instructors miss the mark.

Because, they focus ON going fast.

Which actually slows you down.

We had a saying in the Army for all our training:

“Slow is smooth and smooth is fast.”

To speed up, you need to actually focus on slowing down. Learning every detail until it’s crystal clear in your head before moving onto the next. Otherwise, you end up constantly having to re-learn basic ideas.

And, THAT is what makes learning to code take forever.

In any case, that’s why I teach my courses the way I do. And, explain the WHY behind everything we do and not just show you “what to write”. Sure, it’s a bit slower, at first. But, in my not-so-humble opinion…

You’ll end up learning PHP better than most developers ever will.

And, you naturally pick up speed as you go.

And, in the end, wind up learning the entire curriculum faster.

Anyway, you can get started with my complete PHP curriculum over on SkillShare. Start with my Beginner’s Guide to PHP course to learn core PHP then my Object-Oriented Programming In PHP course.

Then a series of project-based courses to solidify your learning…

PHP Forms.

A Sessions-Based PHP Login Script.

Blogging Application.

It’s all in there. And, you can get started with it all for nothing. Just go here to start the 2-month no-cost trial: https://www.skillshare.com/r/user/johnmorris. Take all the courses. Cancel before the 2 months is up and you never pay a penny.

Maybe the easiest way I know to get “learning PHP” knocked out.

Anyhoo, up to you.

Link is here: https://www.skillshare.com/r/user/johnmorris

Later,

John

July 10, 2018

Why Are Developers Still Learning PHP?

Better question:

“Why are people still asking why are people still learning PHP?”

Sigh.

Anyway, this got asked over on Quora and this Quoran gave one of the better answers I’ve seen. I wanted to share it with you, plus what will be the “canary in the coal mine” to let you know if PHP does ever legit die.

You can listen to the discussion here: https://www.johnmorrisshow.com/332/

Later,

John

July 8, 2018

Static Methods and Properties In PHP

In my last tutorial, What Object-Oriented Programming Is NOT, I mentioned that over-using or mis-using the static keyword is one way developers get confused with object-oriented programming. That, often, they simply take their procedural code, dump into a class, make everything static and away we go.

That said, there CAN be legitimate uses for fully static classes.

I like the answer Pascal MARTIN gave on StackOverflow:

The distinction I make is this:

  • Use an instantiated class for actual objects in your applications (post, category, user, etc)
  • Use a static class for “libraries of code” that have useful functions

As Pascal said, that’s probably over-simplified, but it helps me keep my head straight. Of course, the question becomes… how do we write a static class.

The first thing to keep in mind is “once you go static, you can’t go back”… in a way. More specifically, you can’t use object properties or methods in static methods. So, this won’t work:

<?php
class Library {
public $var = ‘Hey’;

public static function do_stuff() {
echo $this->var;
}
}

Library::do_stuff(); // Triggers: Fatal error: Using $this when not in object context

That’s because $this references and instantiated object. But, we bypass that when using static methods. So, $this essentially doesn’t “exist”. But, you might think you could do this:

<?php
class Library {
public $var = ‘Hey’;

public static function do_stuff() {
echo Library::$var;
}
}

Library::do_stuff(); // Triggers: Fatal error: Access to undeclared static property: Library::$var

So, once you declare a method static… basically everything it touches has to be static, too. Thus, this is what works:

<?php
class Library {
public static $var = ‘Hey’;

public static function do_stuff() {
echo Library::$var;
}
}

Library::do_stuff(); // Outputs “Hey”

One way you might use this, then, is something like this:

<?php
class Library {
public static $date_format = ‘F jS, Y’;

public static function format_date($unix_timestamp) {
return date(self::$date_format, $unix_timestamp);
}
}

echo Library::format_date(time()); // Outputs formatted date

The format_date() method is one that could be used in various places throughout your application and wouldn’t need constantly re-instantiated to use. And, of course, this Library class could contain various, similar methods that have data-agnostic uses. A kind of “catch-all” for miscellaneous functions.

And, of course, as you’ve seen the way to make a property or method static is to simply add the “static” keyword to the declaration, like so:

<?php
class Library {
public static $var = ‘Hey’;

public static function do_stuff() {
// do stuff
}
}

So, there you go. Now, if you want to keep going and learn how to build professional PHP applications using object-oriented programming, then check out my full object-oriented programming course here (also available on Udemy here).

January 2, 2018

Output the last row inserted in MySQLi

MySQLi makes grabbing the last inserted row easy. After running your insert query, you can do this:

$id = $mysqli->insert_id;

Then, you can query for that row like this:

$result = $mysqli->query(“SELECT * FROM table_name WHERE ID = {$id}”);

And, fetch the result as an object:

$user = $result->fetch_object();

From there it’s a simple echo to output it to your page:

echo $user->user_name;

(Although, you’ll want to use htmlspecialchars or htmlentities to escape the output and prevent XSS attacks. But, we’ll save that for another day.)

Simple.

Anyway, in the newly released Module 3 of PHP 101, I show you how to build a fully-functioning PHP form that submits and retrieves data from your database… so you’ll learn how to do this with all the bells and whistles like prepared statements, input filtering, output escaping and more.

It’s a simple proposition…

If you want to master all the ins and outs of MySQL…

This is how you do it.

Right now, you can grab all three modules for just 27 buqs.

That’s 10 buqs off the regular.

Here’s the link

Later,

John

February 21, 2017

Connecting to MySQL with PDO

With MySQLi, it looks like this:

$mysqli = new mysqli($db_host, $db_user, $db_pass, $db_name);

But, PDO is a bit different because it can interact 12 different types of databases: Oracle, PostgreSQL, SQLite, MySQL, Cubrid and several others. So, when using it you have to specify which driver you want to use.

Like this:

$conn = new PDO(“mysql:host={$db_host};dbname={$db_name}”, $db_user, $db_pass);

Notice the “mysql:host=” bit.

For different drivers, you just change out the “mysql” part.

So, PostgreSQL would be:

$conn = new PDO(“pgsql:host={$db_host};dbname={$db_name}”, $db_user, $db_pass);

For Oracle, it’d be:

$conn = new PDO(“oci:host={$db_host};dbname={$db_name}”, $db_user, $db_pass);

And, so on.

Nice thing is…

The code after this doesn’t change for each kind of database. So, you could write the rest of your database interaction code initially for MySQL… then, change to say PostgreSQL.. .and all you have to do is change out the drive designation (mysql, pgsql, oci, etco).

That’s why you hear people recommending you use PDO a lot.

If there’s any chance you might switch to a different database…

It makes sense.

Anyway, this one of the many things you’ll learn inside Module 3 of PHP 101 (which I just uploaded to the site). Along with the basics of CRUD, you’ll learn MySQLi and PDO, prepared statements, building a database class, submitting an HTML for to your database (AND getting data back from it)… and more.

Right now, you can grab all 3 modules for just 27 buqs.

That’s 10 buqs off the regular fee.

Use this link to get it: https://www.johnmorrisonline.com/php

Later,

John

February 16, 2017

Simple input filtering in PHP

Here’s one I don’t see talked about much:

$name = filter_input(INPUT_POST, ‘name’, FILTER_SANITIZE_STRING);

What this does is grab the “name” element from your POST array and run it through the the filter: FILTER_SANITIZE_STRING… which removes all HTML tags from the string (since we know a person’s name doesn’t have HTML in it).

It’s a really simple way of quickly filtering your data.

Here’s another:

if ( ! $email = filter_input( INPUT_POST, ’email’, FILTER_VALIDATE_EMAIL ) ) {
die(‘Invalid email’);
}

This one validates the submitted email address.

And, returns false if it’s invalid.

Again, a very simple way of quickly validating your data.

And, there’s a roughly 20-30 different filters you can run your data through. Things like: FILTER_VALIDATE_URL, FILTER_VALIDATE_INT, FILTER_SANITIZE_SPECIAL_CHARS, FILTER_SANITIZE_EMAIL and more.

The idea here is:

  1. Filter data like this on input
  2. Escape it on submission to MySQL
  3. Escape it on output to the browser

That little routine will help you prevent invalid data, SQL injection, XSS attacks and whole host of other problems.

Anyway, it’s one of the things I show you in Module 3 of PHP 101. Along with, of course: CRUD basics, PDO, MySQLi, Prepared Statements… plus building a database class AND submitting HTML form data to MySQL using all of this.

Use this link to get the details on the course and grab Modules 1-3: https://www.johnmorrisonline.com/php

Later,

John

February 10, 2017

Why I don’t use PHP frameworks

“They all suck!”

That’s straight from the horse’s mouth.

Rasmus Lerdorf, the creator of PHP.

He went on to say:

“While they all suck. Everyone needs a framework. What everyone doesn’t need is a general purpose framework. Nobody has a general problem. Everyone has a very specific problem they’re trying to solve. And a general purpose framework, while it can solve it, it usually solves it in a way that you get so many other things that you don’t need… that ends up being done on every request.”

He goes onto recommend using “targeted frameworks” for targeted problems:

“Usually, I tell people to look for a targeted framework. So, if you have a problem that looks a lot like a blogging problem. Maybe, WordPress should be your framework… if your problem is very close to something WordPress can handle, chances are, you’ll be using most of WordPress. There won’t be all these other general purpose things you won’t touch.”

Dude must be stalking me.

Cuz, that’s what I’ve been saying.

While everyone else is getting all sweaty in the shorts about the latest and greatest framework or tool… I’ve generally avoided them and kept things pretty simple. And, frankly, have only benefited from it.

Anyway, there’s no need to re-create the wheel.

And, the general purpose frameworks… while they’re great and can do some cool things, they’re usually overkill for what you need and not “modularized” enough to where you can only use certain parts and kill the rest.

You’re stuck with all-or-nothing.

I’m sure there are exceptions…

But, for me… WordPress is my “framework”.

Of course, I’m not saying it has to be yours. I know some of you just snorted at the horror of me using “dirty old WordPress” as my framework. What a pleeb! But, the lesson is to find a targeted “framework” (whether it’s technically a framework or not) and using it for the specific problems it solves.

Or just go neked… with straight PHP.

And, don’t think you need to learn all these frameworks like Laravel and whatnot.

Or that they’ll be a “perfect” solution to your problem.

Maybe.

Probably not.

Anyhoo, take that for what it’s worth.

Of course, if you want to be a total boss and just code straight in PHP then hop your hard core little tookus on over to this PHP tutorial. You’ll quickly learn the PHP skills you need to start getting paaaid to write code for a living for less than I spent on McDonald’s this morning.

Go now child: https://www.johnmorrisonline.com/php

Later,

John

February 2, 2017

Is PHP Dead?

Critics have been saying PHP was dead for years now.

But, here it is… still tickin’ away… picking up market share and powering the web. Matter of fact, one of the harshest criticisms I’ve seen on PHP… comes from a WordPress blog. Ya know, built on PHP.

But, with the rise of frameworks like NodeJS and the resurgence of Python…

Has PHP seen its last days?

Should you invest time learning it?

Or, will it be obsolete in 5 years?

I tackle that in today’s podcast. Give it a listen

Plus, I snuck in a damn good “treatise” on freelancing. Worth listen in my totally bias but humble opinion.

If you get value, be sure to like it and also share it with the developers you know so we can reach as many as possible and help them to make their IT career dream come true, as well.

And, get access to all the perks mentioned in the show as a supporting listener on Patreon: https://www.johnmorrisonline.com/patreon.

Or enroll in my new PHP 101 video course and get the exclusive interview I did with Mike P.

P.S. If you liked the show, give it a like and share with the communities and people you think will benefit. And, you can always find all my tutorials, source code and exclusive courses on Patreon.

September 6, 2016

PHP cURL Tutorial and Example

A simple PHP cURL tutorial and example. Learn how to use curl_init, curl_setopt, and curl_execute. Also learn how to POST data to a remote URL using cURL.

Ready to learn even more PHP? Take my free Beginner’s Guide to PHP video series at https://www.johnmorrisonline.com/learnphp

Get this source code along with 1000s of other lines of code (including for a CMS, Social Network and more) as a supporting listener of the show at https://www.johnmorrisonline.com/patreon

P.S. If you liked the show, give it a like and share with the communities and people you think will benefit. And, you can always find all my tutorials, source code and exclusive courses on Patreon.

August 16, 2016