/** * * Bind the values for CRUD using the PDO bindValue. * In case of table we use the type to bind the values accordantly. * In case of custom SQL we use the default PDO::PARAM * * @param resurce $stmt the prapared statement * @param array $binds array containing the value for binding * @param array $types array containing the type of the field * @return boolean true on success */ public static function bindValues($stmt, $binds, $types) { //PDO::PARAM_BOOL, PDO::PARAM_NULL,PDO::PARAM_INT,PDO::PARAM_STR,PDO::PARAM_LOB foreach ($binds as $key => $field) { if ($field === NULL) { $stmt->bindValue($key + 1, NULL, PDO::PARAM_NULL); continue; } switch ($types[$key]) { case 'numeric': case 'string': case 'date': case 'time': case 'datetime': $stmt->bindValue($key + 1, $field, PDO::PARAM_STR); break; case 'int': $stmt->bindValue($key + 1, (int) $field, PDO::PARAM_INT); break; case 'boolean': $stmt->bindValue($key + 1, $field, PDO::PARAM_BOOL); break; case 'blob': $stmt->bindValue($key + 1, $field, PDO::PARAM_LOB); break; case 'custom': $stmt->bindValue($key + 1, $field); break; } } return true; }
/** * save image in to destination * @param resurce $image * @param string $name * @param string $dest full path with file name */ protected function imageSave($image, $dest) { //prepare folder $this->makeFolder(dirname($dest)); //prepare to save if ($this->format == 'jpeg') { $image->setCompression(Imagick::COMPRESSION_JPEG); $image->setCompressionQuality($this->quality_jpeg); } //save image if (!$image->writeImage($dest)) { throw new RuntimeException('Cannot save image ' . $dest); } return true; }