Unlike SQL Server, String concatenation works using a function. It’s a simple function that you pass comma separated values into in the order you want
How to do Email Validation
Using the PHP filter_var function we can test email addresses for valid format and only unicode characters. Example usage below.
Query using Avg Ignoring Certain Values
In this case we want to get the average of values but we also want to ignore certain values, say if when the deviceType column
Replace All Characters In a String that Aren’t Alphanumeric
Using the preg_replace function you can easily replace all characters in a string that are not alphanumeric. This can be useful for sanitizing a string
Auto Selecting Input Field Contents on Mouse Entering Field
You can do this simply with an onclick event like below.
Add an Image to the DOM Dynamically
This example will work fairly well cross-browser. In IE it will use new Image and everything else it will use createElement. There are bugs in
Select Last N Characters of a Field
Using the substring function, this example below will select the leftmost 6 characters from a string field named “field_name” in the table tbl_stuff with mysql.
Seeing Full Warnings That Just Happened After a Query
After you run a query on MySQL server you may get warning messages. To see the complete warnings you simply run the command show warnings.
How To Check the SHA Hash of Files
When you download software online often the publisher will also provide a file hash to make sure that the file hasn’t been modified or hacked
coalesce Function Handy for Outer Joins and Nulls
The built-in function coalesce in MySQL is great for outer joins where the return or expected answer can be null. Coalesce can be used anytime