Category Archives: Development

Simple.Data.SQLite referencing wrong version [SOLVED]

I started to use Simple.Data.SQLite and would install through Nu-get and noticed Simple.Data tried to reference System.Data.SQLite version 1.0.91.0 while Nu-get would only install vserion 1.0.94.0

This would cause an error while trying to compile and it would fail.

The error would be described as below:

 

System.IO.FileLoadException: Could not load file or assembly ‘System.Data.SQLite, Version=1.0.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139’ or one of its dependencies. The located assembly’s manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

SOLUTION

To fix this, I added an entry into the app.config file to point version 1.0.91.0 to the newer version 1.0.94.0

 

 

PHPStorm Live templates for PDO & PureCSS framework

Wanted to post Live Templates for phpStorm for PDO examples and for the quick PureCSS Framework ( http://purecss.io/ ) that I’ve created. I plan on updating the files as I add more to them.

PDO:

http://www.jmrowe.com/resources/livetemplates/PDO.xml

PureCSS:

http://www.jmrowe.com/resources/livetemplates/Pure.xml

Right-click the link to “Save link as..” and save in your .WebIde -> config -> templates folder to inspect/use the templates.

Creating an array from a list of items in a $_POST variable

Routinely, I’ll find my self creating forms that will take a list of items in a textarea that was pasted from another program like Excel ( column of data ). Furthermore, I will usually take this list of data and explode it into an array to be processed individually.

Using the explode function in php is simple, however, when separating items in the $_POST array by a newline – the newline may be different based on the type of php server.

\n is used for Unix systems (including Linux, and OSX).

\r\n is mainly used on Windows.

\r is used on really old Macs.

To avoid these differences, you can use the php constant PHP_EOL .

If we had a textarea named “list” – then it would look like:

 

Proper way to check if POST variable is actually set and not a empty string or NULL

Most people use isset to check if a POST variable  ( i.e. isset(_POST(‘textfield’))  ) has been entered. However, as the table displays below, if the user enters an empty string ( “”) isset will give an unexpected result.

Instead we should use the following:

 

The combination of array_key_exists and empty will check if the value is not only set but also not an empty string ( “”) or NULL.

Value of variable ($var) isset($var) empty($var) is_null($var)
“” (an empty string) bool(true) bool(true) bool(false)
” ” (space) bool(true) bool(false) bool(false)
FALSE bool(true) bool(true) bool(false)
TRUE bool(true) bool(false) bool(false)
array() (an empty array) bool(true) bool(true) bool(false)
NULL bool(false) bool(true) bool(true)
“0” (0 as a string) bool(true) bool(true) bool(false)
0 (0 as an integer) bool(true) bool(true) bool(false)
0.0 (0 as a float) bool(true) bool(true) bool(false)
var $var; (a variable declared, but without a value) bool(false) bool(true) bool(true)
NULL byte (“\ 0”) bool(true) bool(false) bool(false)

Table Credit to: @virendrachandak on Twitter