Binding extra variables with PHP PDO returns no results As I expand the data binding layer for my travelblog.ws project, I keep coming across different ways of breaking the PHP PDO statement class. The recent peculiarity that I've come across was to do with binding more variables than there were bind parameters in the SQL statement. In this situation, PDO will not return any data. In fact this is documented in the API...
PHP PDO doesn't work binding multiple IN statement values PHP's PDO is a great way to access databases and works as expected on the most part, that is until you come to the IN() operator. Some peculiarities begin to emerge there as I've discovered recently when updating code for my travelblog.ws project.
MySQL always returning 0.999 for DECIMAL type fields I've started to use the DECIMAL type in MySQL to store longitude/latitude coordinates recently and for some reason no matter what value I stored, when queried back I'd always get '0.999'. A little bit of investigation and I found the answer so lets see what was going wrong.
Getting the total number of rows with MySQL LIMIT clause The MySQL SELECT statement syntax includes a LIMIT clause that can be used to restrict how much data is returned from the database. This is fantastic for pagination but in most cases you also want to know how many rows there are in total, which typically requires a second query. With MySQL there is a special option that can be passed to SELECT to do this calculation for you automatically.
How to set MySQL connection timezone with PDO For my travelblog.ws project I store all dates as UTC in columns using the DATETIME data type i.e. my code converts dates to UTC before storing them. Because DATETIME is time zone agnostic this worked great, that is until I needed to use the TIMESTAMP data type on a number of new columns that I've added.