Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Three Devs and a Maybe:
Episode #98 - Instant Feedback on your Pizza Oven
May 19, 2016 @ 09:20:35

The Three Devs and a Maybe podcast has released their latest episode today - Episode #98: Instant Feedback on your Pizza Oven, a discussion on quick feedback cycles, MVCC in Databases and Type Systems

On this weeks episode Edd and Mick start off discussion around productivity, quick feedback cycles with clients and building pizza ovens. We then move on to chat about how Edd ‘maybe’ accident prone, how MVCC works at a high-level and why you need to vacuum your tables in Postgres. Finally, we bring up Uncle Bob’s recent ‘Type Wars’ article and highlight the different variants of typing (static, dynamic, weak and strong).

You can listen to this latest episode either using the in-page audio player or by downloading the mp3 directly and enjoying at your leisure. If you enjoy the show, be sure to subscribe to their feed and get the latest updates on new shows as they're released.

tagged: threedevsandamaybe podcast ep98 feedback mvvc database typing pizzaoven

Link: http://threedevsandamaybe.com/instant-feedback-on-your-pizza-oven/

Rob Allen:
Using Eloquent in Slim Framework
Apr 07, 2016 @ 09:45:31

Rob Allen has a quick post showing how to use Eloquent in a Slim framework application to work with your database queries and functionality.

Eloquent is one of the easier ORMs to get started with, so let's look at how to use and test it within a Slim Framework application. [...] Eloquent is quite a nice implementation of the Active Record pattern. If that meets your needs, then it is easy to use within a Slim Framework application, so go for it!

He walks you through the set up of the Eloquent package via a Composer require and update your Slim configuration with the database settings. He then includes the few lines you'll need to use the "capsule" manager to integrate it with the Slim structure. He also talks about testing models and shows how to create some simple tests with PHPUnit and a bit of mocking.

tagged: slimframework eloquent database capsule composer tutorial

Link: https://akrabat.com/using-testing-eloquent-in-slim-framework/

Toptal.com:
Handling Intensive Tasks with Laravel
Apr 05, 2016 @ 12:48:36

The Toptal blog has a post for the Laravel users out there showing you how to handling intensive tasks in your applications. In this case it's creating a background job (run via cron) to import information from Excel spreadsheet formatted file into the database.

When dealing with time consuming resource intensive tasks, most PHP developers are tempted to choose the “quick hack route.” Don’t deny it! We’ve all used ini_set('max_execution_time', HUGE_INT); before, but it doesn’t have to be this way.

In today’s tutorial, I demonstrate how an application’s user experience may be improved (with minimal developer effort) by separating long-running tasks from the main request flow using Laravel. By making use of PHP’s ability to spawn separate processes that run in the background, the main script will respond faster to user action.

He starts with why PHP isn't particularly a good choice for long running requests and how making users wait for it to complete is a bad thing. He then walks you through the setup of a basic Laravel application that includes the maatwebsite/excel library for the Excel handling. He shows his configuration setup, both in the Nginx and Laravel side, to handle serving up the app. He uses Laravel migrations to set up the database and the models, routing and logic (controller) to handle the incoming Excel file for import. With this in place he then creates the command type to process the file and save the information it contains to the database. Finally, he ends the post with the cron configuration you'll need to handle the import, running it nightly at midnight.

tagged: tutorial intensive task excel import database laravel

Link: https://www.toptal.com/laravel/handling-intensive-tasks-with-laravel

Gonzalo Ayuso:
Foreign Data Wrappers with PostgreSQL and PHP
Feb 22, 2016 @ 09:43:48

Gonzalo Ayuso has posted a quick tutorial to his site showing you how to work with Foreign Data Wrappers on your PostgreSQL database in PHP. If you're not familiar with the data wrappers functionality, you can find out more on the PostgreSQL wiki.

PostgreSQL is more than a relational database. It has many cool features. Today we’re going to play with Foreign Data Wrappers (FDW). The idea is crate a virtual table from an external datasource and use it like we use a traditional table.

He gives an example of a simple RESTful service with a Silex application serving up a set of user data (names). He then switches over to the PostgreSQL side and shows how to create the data wrapper and set up the mapping of it to the REST server's location. With that set up you can then select from the data returned as if it were a normal table with a slight caveat - filtering (like with where) must be done server side, not via the SQL statement.

tagged: postgresql tutorial foreigndatawrapper datawrapper database rest service

Link: http://gonzalo123.com/2016/02/22/foreign-data-wrappers-with-postgresql-and-php/

SitePoint PHP Blog:
3 More Joins You Should Be Familiar With
Feb 08, 2016 @ 12:18:36

On the SitePoint PHP blog Zach Wallace shares more database wisdom with his readers introducing three more JOINs you should know in your development work.

There are many ways to JOIN data from two database tables and filter the information you require. Craig Buckler wrote a popular piece on understanding JOINs; namely INNER, LEFT, RIGHT, and FULL OUTER. This article is an extension of that one.

He starts with the data he'll be working with: customers and books, linked by a book_id column. He then quickly reviews some of the joins already discussed in the previous article (LEFT, RIGHT, OUTER, INNER) before getting into the newer, more powerful types:

  • LEFT JOIN with Exclusion
  • RIGHT JOIN with Exclusion
  • OUTER JOIN with Exclusions

He finishes the post with a few other thoughts about using WHERE clauses in JOINs, the CROSS JOIN and how the JOINs relate to each other in MySQL.

tagged: join database three list inner outer left exclusion advanced example tutorial

Link: http://www.sitepoint.com/3-more-joins-you-should-be-familiar-with/

Laravel News Podcast:
LN 08: Database Backups
Jan 28, 2016 @ 12:56:39

The Laravel News podcast with host Eric Barnes has posted their latest episode: Episode 8 - Database Backups.

Episode 8 of the Laravel News podcast is now out.

This episode features special guest Freek Van der Herten talking about backups, Test Driven Laravel, WordPress & Laravel, and PDF generation.

You can listen to this latest episode either by subscribing over on iTunes or pointing your feed reader at the RSS feed and grabbing the latest from there. If you're interested in listening to previous episodes, be sure to check out the podcast archive section on the Laravel News site.

tagged: laravelnews laravel podcast news ep8 ericbarnes database backup

Link: https://laravel-news.com/2016/01/ln-08-database-backups/

Paul Jones:
Atlas: a persistence-model data mapper
Dec 30, 2015 @ 09:48:50

Paul Jones has a new post to his site about a library he's worked up to provide "persistence-model data mapper" functionality for you to use in your PHP applications in accessing your database.

Atlas is a data mapper implementation for your persistence model (not your domain model).

As such, Atlas uses the term "record" to indicate that its objects are not domain entities. Note that an Atlas record is a passive record, not an active record; it is disconnected from the database. Use Atlas records indirectly to populate your domain entities, or directly for simple data source interactions.

The library is mostly an experiment on his part to create a tool that allows switching from the Active Record pattern to Data Mapper pattern for accessing your database without much hassle. The README on the library shows some of the basic usage of the tool, including the usual CRUD (create, read, write, execute) functionality.

tagged: atlas persistence model datamapper activerecord designpattern database library

Link: http://paul-m-jones.com/archives/6210

Lorna Mitchell:
Insert Data with Phinx
Dec 18, 2015 @ 10:49:07

Lorna Mitchell has a new post to her site with a quick tip for any of the Phinx users out there around a new feature they've added: database seeding.

Database patching is a wicked hard problem, one that's got a bit easier in my world lately as I've been using Phinx on a few projects. [...] One thing I didn't immediately find was how to insert data. Phinx has seed functionality but in this case I needed to put in a lookup table to go along with a data structure change.

She includes a code examples of this new feature, showing how to create a roles table and seed it with a new record with a "name" value of "admin". She also mentions one "gotcha" in the name of the function used to save the data to the new table (saveData versus just save).

tagged: phinx insert data database migration example tutorial

Link: http://www.lornajane.net/posts/2015/insert-data-with-phinx

Kevin Schroeder:
Configuring MySQL SSL in Magento
Sep 28, 2015 @ 09:24:34

Kevin Schroeder has a quick post to his site showing the Magento users out there how to configure the SSL connection to their MySQL database backend.

’ve been asked a few times now if there is a way to use encrypted MySQL connections in Magento. [...] The answer, to my surprise, is that there is no way of doing it out of the box.

[...] All database configurations are stored in the local.xml file and the XML specification does not allow numbers for XML node names. So no matter how you try to slice it it looks like getting the SSL settings into the Magento adapter will not work without a code change. The Internet seems to confirm this. But that doesn’t mean that it can’t be done. So I wrote a quick Magento adapter that allows you to pass in the constant values.

He walks you through the process of getting the adapter installed, configuring MySQL to allow for the SSL connections and the configuration change to make. He includes the XML you'll need to update, including the addition of a secure_driver_options to the XML to provide the necessary SSL connection information.

tagged: magento mysql adapter ssl connection configure database

Link: http://www.eschrade.com/page/configuring-mysql-ssl-in-magento/

Fortrabbit.com:
Is your database password stored safely?
Sep 08, 2015 @ 11:48:18

The Fortrabbit blog has a post that want to help you store your database password securely and away from prying attacker eyes. While they use the example of a a database password, credentials for just about any other service could be protected the same way.

How do you protect your access data? Your sensitive secrets, basically anything your PHP application uses to authenticate or authorize with other services such as databases, caches, cloud storages, image resize services, transactional mail providers. All of them. Where do you put this — easily accessible while in development and secure for production?

They start by pointing out a few places where they should not be stored: in your code, in a version control system or in an environment variable (plain text). Instead, they suggest using a combination of a secret key that's configured in the application and encrypted versions of the values in environment variables. Some code is included showing how to set this up in a Laravel-based application, but the principle can be applied independent of the framework too with some other simple tools. They end the post with some links to other articles including a "considered harmful" piece reinforcing their methods.

tagged: credential protection password database tutorial encryption environment variable

Link: http://blog.fortrabbit.com/how-to-keep-a-secret