MySQL Bitwise Operators: User Permissions Example

So here is another 'better late than never' discovery of mine: MySQL bitwise operators. For reasons of efficiency, it is far better to do something in a MySQL query than looping through the results and applying it using PHP and this is a great tip for that. I came across »

Using LIMIT in a MySQL Subquery: An Alternative

When attempting to pull some database data a short time ago, I assumed the solution to the particular problem would be to use LIMIT in a MySQL subquery. Admittedly, this was something I'd never had to do before so it surprised me a bit when MySQL gave me this error »

MySQL JOIN a Table to Itself

When we think about joining tables with* JOIN* in MySQL, we usually have two or more tables that we want to link together based on common columns. Until I needed to do so recently, I didn't consider the idea of using a JOIN to join a table to itself, even »

Querying Data with MySQL Joins and Subqueries

This article provides an example to show how MySQL joins and subqueries can be used within a query to get database data. Let's say that you have two tables containing related information*. The first of these is called 'posts' and stores details about blog posts made on a site such »

Writing a Conditional Insert Update Query: MySQL and PHP

Commonly, program logic is needed to determine whether to execute an INSERT or an UPDATE query based on a particular condition (a conditional insert update query). Often this condition is usually whether or not a certain record already exists in the database table. This article looks at INSERT DUPLICATE KEY »

MySQL Aliases

MySQL Aliases are used within MySQL query syntax to give temporary (usually shorter/more readable) names to database tables and columns. The syntax rule for MySQL aliases is: [table/column name] AS [alias] or: [table/column name] AS [“my alias”] The second rule applies when an alias contains spaces and »

Using Database Transactions: PDO Code Example

Following on from a previous article that gave an overview of database transactions, this post contains a basic example that shows how you might implement MySQL transactions in the context of an online appointment booking system using PHP's PDO (PHP data Objects) extension. In contrast to the other frequently used »

Using Database Transactions

As a newcomer to PHP, database storage, and programming in general I was keen to get hold of a few books on these subjects to help me get started. However, it seems to me that more often than not, database transactions are included as a bit of an after-thought; a »