Posts tagged with “php

Using MySQL DATE_SUB to SELECT rows relative to a date range

DATE_SUB can be very handy if you’re trying to return rows from a database table relative to a date range. As the name suggests, it SUBtracts a time value from a DATE. It expects a date, as well as an INTERVAL argument consisting of a unit (such as DAY, WEEK, or YEAR) and quantity, like […]

Fixing garbled htmlentities output by using the proper charset

If you’re running user-provided text through htmlentities and it’s coming out garbled, it’s likely that the page’s charset doesn’t match the one you used to encode the text. First, we confirm the encoding charset. Starting with PHP 5.4, the default charset is UTF-8, so assuming you’re running a reasonably modern version of PHP and you […]

Configuring a php.ini file for AddOn Domains hosted on GoDaddy

UPDATE It appears GoDaddy no longer supports multi-domain php.ini files. Instead, one has to put an ini file at the root level of each hosted domain. For the primary domain, the ini file would go in ~/public_html/. For AddOn Domains, the ini file would go in ~/public_html/[AddOn Domain]/. For instance, if the domain for the […]

Installing and using Composer

Composer is a dependency-management tool for PHP. It installs and keeps current all library dependencies for a given project. It does so recursively, so not only does it manage all direct dependencies but any dependencies those dependencies have, and so on, and so forth, ad infinitum, ad nauseum. It’s becoming more popular as an installation […]

Using SELECT in a MySQL INSERT Command

I wrote recently about using JOIN when needing to incorporate a lookup in a MySQL delete command. What if one needs to do the same when inserting into a table instead? This time it’s SELECT to the rescue. Imagine we have a simple bookmarking function that stores a user id and article id in a […]

Using JOIN in a MySQL DELETE Command

Deleting from a table is simple enough. If, for example, we wanted to remove all the comments from a single user and we already know that user’s id we could run this command (employing the EasyPDO library in PHP): <?php $db->ExecuteSQL(“DELETE FROM comments WHERE user_id=?”,”i”,$id); ?> Now imagine we only have the user’s email and […]