Fixing pgsql invalid integer errors with php type casting