OpenLampTech issue #120
Default MySQL config | WooCommerce paid orders only | Top open-source e-commerce solutions | PHP Enums | PHP switch statement woes | PHP Superglobals
Thank you for reading the OpenLampTech newsletter!
If someone awesome shared this newsletter with you and you are not yet subscribed, please use the Subscribe button below and join:
OpenLampTech has sponsorship opportunities for your brand, product, or service in the weekly newsletter. As an independent publication, collaboration is very affordable.
All commentary is mine unless otherwise quoted.
SQL Joins: Inner, Outer, Left, and Right Joins
If you're working with a normalized database, you will use some JOIN
s at some point. In some specific instances, you may get the data you need using a UNION
[ALL
]. But, you may as well learn all you can about the SQL JOIN
and how they are not all created equal. I learned the hard way about missing data because I was using an INNER JOIN
when I should have been using a LEFT JOIN
.
This article is a good, simple primer on JOINS
. Even if you utilize an ORM, take time to know the JOIN
(s).
[Medium]
Understand The Default MySQL Configuration
While some of the content here is specific to Bitnami, much of the default MySQL configuration covered in this piece is the same found in other MySQL installs.
I think learning more about the default configuration is a good thing. Especially, when you want/need to do any performance tuning and configuration changes.
(Side note: If you need any performance tuning done for your web application's database, you should learn more about Roman Agabekov and Releem in this OpenLampTech interview)
[bitnami.com]
Mastering Enums: Elevate Your Programming Skills
PHP 8.1 included support for Enums.
Enums are custom types with a specific set of values and can be used as other objects.
In this article see an example use case for an enum as a user-provided sorting order. I've not (yet) used Enums in any code but the more I learn about them, the more I plan to start trying to implement them where it makes sense.
[Medium]
PHP superglobals are available anywhere in your application code, most of which are associative arrays. PHP has 8 superglobals built right into the language allowing you to retrieve their information from any script without the use of GLOBAL
. There are equivalent constants for each superglobal covered in the article as well (of which I was unaware).
[Medium]
Be careful about the switch statement in PHP
The switch statement in PHP helps you without the need for many/multiple nested if
/elseif
/else
statements, which can result in some messy code. However, there is a caveat (perhaps a poor word choice on my part) in how comparisons are made because switch
uses loose comparisons (==
).
This article shares a couple of alternatives so you can avoid this type of (potential) bug creeping into your code, one of which is match
- available in PHP 8.
[dev.to]
First Row of Many Similar Ones
As is formed in the article, the LIMIT
clause will not work (correctly) in this context.
In those cases where you need to know perhaps the largest amount spent by each customer and limit those rows to some number (e.g., 1) on a per-customer basis, this is where you would need Window Functions (for MySQL at least).
I encourage all developers to become familiar with Window Functions as they are quite powerful and often more performant than a massive spaghetti query.
[SQL For Devs]
WooCommerce: Retrieve Paid Orders Only
More great content from the fantastic Business Bloomer website, which is the de facto source of WooCommerce coding tips.
See an example of using the wc_get_orders()
function to retrieve those orders per a specific payment provider (e.g., PayPal, Stripe, etc…)
Using the PHP array_merge()
function, you can include multiple different payment providers because the argument for wc_get_orders()
only accepts one.
[Business Bloomer]
The top 12 open source ecommerce platforms in 2024 (+alternatives)
Similar to WooCommerce, many of these e-commerce solutions run on other open-source CMSs like Drupal and Magento. For others, foundational PHP frameworks like Symfony power their e-commerce engine. With all of these options (and more) one might think open-source e-commerce is the only way. And, it could be but you can't ignore other big players like Shopify (Shopify is not open source). I think in some situations, Shopify might be the better choice. However, I would still lean towards WooCommerce as that's what I'm somewhat familiar with, and I can utilize PHP knowledge and skills there.
[Nexcess]
Also, my favorite framework has an update:
CodeIgniter 4.4.6 Release (February 27th, 2024)
WooCommerce news and updates
WooCommerce 8.7 Beta: Receipt rendering engine & More (February 27th, 2024)
Thank you for reading. I hope you have a great rest of your week.
Take care.
Josh Otwell
OpenLampTech is a reader-supported publication. You can support the publication with a virtual coffee for as little as $3 (USD).
[#Classifieds, #Affiliates, #Click Ads, #Shoutouts]
🤝 OpenLampTech earns a small commission (or payment/gain in some form) from many of these links. Your support helps keep the weekly OpenLampTech newsletter free for readers.
Take your Laravel applications to the next level with Battle Ready Laravel by Ash Allen. Learn how to improve the performance, maintainability, and security of your Laravel projects in this e-book.
The online DNS course for developers. Learn more at Nslookup.
AI-powered SQL generator and data analytics tool. Learn more at SQLAI.ai - AI, SQL & DATA.