PHP

Simple PHP CSV Class

Throughout my years in programming I've dealt a lot with reading and importing CSV files, exporting queries into CSV files, and building dynamic CSV files. I decided it was time to create a simple PHP class to do all this work for me.

With this class you can change the terminator, separator, enclosed, and escaped characters as well as mime type. You decide the file name and there are simple built in functions to let you easily navigate the rows and columns of the CSV.

The class is compatible with newer AND older (less than 5.3.0) versions of PHP.

Sorting Arrays by Sub Array Values using PHP

Multidimensional arrays are very handy for storing lots of data in one array variable opposed to creating and having to manage many individual array variables. For example, let's say we need to store all of our employee's data. Instead of creating many different arrays, one for each employee, we can simply create a multidimensional array, and store all of the employee's data within that.

Multidimensional Array that we will sort

Killing MySQL Queries that exceed a timeout using PDO and PHP

Here is an easy way to kill queries using PDO connection method with MySQL. Note that you can NOT kill queries using a "prepared" string. It must be done using "query".

The first step is to grab the PROCESSLIST.

PDO Connection Basics and Examples using PHP

Here are some PDO connection method basics with examples.

You will often commonly see the connection method being referred to as $dbh and $sth. These simply stand for "database handler" and "statement handler".

Connecting to MySQL with PDO Object

Simple PHP Class used for uploading files and images

I wrote a simple PHP class that may be used for uploading and deleting files or images. This code allows the programmer to set the destination, file name, required extension, and max file size. The PHP class checks the file validation with its own internal functions and stores the errors or will automatically print the errors on screen if that is how you want them handled.

PHP Simple File Manager

Submitting multipart/form-data using jQuery and Ajax

It is possible to submit files using "multipart/form-data" and ajax. There are many sites out there that show complicated ways of doing this when it is really easy. It simply requires a little configuration of the jquery ajax process and grabbing your form data using the FormData() function.

Using the following method, you can submit multiple files and are not just limited to one.

Lets take a look at our form.

Setup a simple cURL connection to POST data using PHP

cURL is used to send "POST" data from one web page to another behind the scenes.

If cURL is enabled on your server, it is fairly easy to setup. I had trouble finding a page that broke setting up a cURL connection down to its most simplest form by showing a cURL example, so I decided to post a page for it.

Example: cURL setup with PHP

Update MySQL PDO Function

Below is a PDO update function that I wrote to save me time from
constantly constructing the PDO update query whenever I need it. Now I
simply pass my values and fields to the function and all is taken care
of.

Insert to MySQL PDO Function

Below is a PDO insert function that I wrote to save me time from
constantly constructing the insert query whenever I need it. Now I
simply pass my values and fields to the function and all is taken care
of.

Connect to MySQL database using PDO

Below is how to set up a PDO connection to a MySQL database.

Pages

Subscribe to RSS - PHP
If you have questions about anything on this site, you can find me on Google+: