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

Stovepipe Systems:
Using bitwise instead of booleans
Aug 18, 2016 @ 16:18:44

On the Stovepipe Systems blog there's a new post from Yannick de Lange that suggests using bitwose operations instead of booleans to evaluate an on/off setting.

The naive way of storing many boolean options (in a database) is to create for each option a field and storing a 0 when it is false and 1 when it is true. Which of course works, but adding options will require a new field, which might require creating a compatibility layer for your old data. There is an easier way to do this and it's even more efficient at checking fields.

This brings me to an old topic which I have to explain to all the new people at some point and even once explained not everybody understands how it actually works. So in this post I'm going to explain how to use bitwise operators and how it works internally.

He starts with a common example using the 0/1 storage method and refactors it a bit to use different values that are more compatible with bitwise operations. He includes the usage of this system and how to works to evaluate multiple potential option values.

tagged: bitwise option boolean storage enable setting tutorial

Link: http://stovepipe.systems/post/using-bitwise-instead-of-booleans

Evert Pot:
MySQL 5.6 BOOL behavior when using PDO and prepared statements
Dec 05, 2013 @ 16:37:42

Evert Pot was seeing some weird issues with his MySQL BOOL usage via PDO when he upgraded to one of the latest versions (5.6). Thankfully, he's shared his solution to the problem as well as the symptoms he was seeing when it was causing problems.

I recently updated my workstation to run MySQL 5.6.13. It didn't take very long for things to start breaking, and since I couldn't find any other information about this on the web, I figured this may be useful to someone else. The main error that started popping up was: "Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '' for column 'my_bool' at row 1' in test.php" This exception happens under the condition that you use PDO, prepared statements and booleans.

He includes a small sample script to reproduce the issue and points out the issue - the default casting of prepared values to strings in prepared statements with PDO bound parameters. He shows two "relatively easy solutions" to the problem - either using integers instead of the true/false PHP boolean or specifying a type with the bindValue call.

tagged: mysql upgrade boolean field pdo prepared statement

Link: http://evertpot.com/mysql-bool-behavior-and-php/

DevShed:
Validating Boolean Values and Float Numbers with Filters in PHP 5
Aug 06, 2009 @ 12:51:05

Continuing their "validation in PHP" series, DevShed has posted this new tutorial looking at the validation of boolean values and float numbers in PHP5 applications (with the filter extension).

As you learned in previous parts of the series, the filter extension permits you to validate elements of a given array very easily as well. Therefore, in this fourth chapter I'm going to explain how to check for Boolean values in arrays, as well as how to validate float numbers using another handy filter.

the examples are pretty simple, running a filter_var on the values to check if it's a boolean and to require that the set of values comes in as an array.

tagged: tutorial boolean filter extension float

Link:

DevShed:
Checking Boolean Values with Filters in PHP 5
Jul 30, 2009 @ 14:09:12

DevShed continues their look at filtering in PHP5 applications with this third part covering checks on boolean values.

As I said before, the filter extension can be used for more than validating integers, since it provides the required functionality to checking other data types. Thus, in the next few lines I'm going to discuss how to use the extension for validating Boolean values.

They give a few lines of example code to show how different values (like "1" versus 1 and "true" versus true) are affected by PHP's dynamic typing.

tagged: boolean value tutorial filter extension

Link:

DevShed:
Performing Full-text and Boolean Searches with MySQL
Jun 06, 2007 @ 19:06:00

DevShed has started a new MySQL-centric series today with this new tutorial, an initial look at working with MySQL and PHP to perform full-text and boolean searches on your data.

In this series of articles I'm going to show you how to work with full-text and Boolean searches using MySQL and PHP 5, but the entirety of the code samples that will be developed here can be easily modified to work with a different database server.

They start with the creation of a "common approach" for making the requests and fetching the results (in classes so that any other database could be substituted). With the class structure in place, they move on to the full-text searches, showing how to format database tables by creating them with a fulltext index on which ever fields you want.

tagged: mysql boolean search fulltext table database tutorial mysql boolean search fulltext table database tutorial

Link:

DevShed:
Performing Full-text and Boolean Searches with MySQL
Jun 06, 2007 @ 19:06:00

DevShed has started a new MySQL-centric series today with this new tutorial, an initial look at working with MySQL and PHP to perform full-text and boolean searches on your data.

In this series of articles I'm going to show you how to work with full-text and Boolean searches using MySQL and PHP 5, but the entirety of the code samples that will be developed here can be easily modified to work with a different database server.

They start with the creation of a "common approach" for making the requests and fetching the results (in classes so that any other database could be substituted). With the class structure in place, they move on to the full-text searches, showing how to format database tables by creating them with a fulltext index on which ever fields you want.

tagged: mysql boolean search fulltext table database tutorial mysql boolean search fulltext table database tutorial

Link:


Trending Topics: