本文整理汇总了PHP中DBConnect::prepare方法的典型用法代码示例。如果您正苦于以下问题:PHP DBConnect::prepare方法的具体用法?PHP DBConnect::prepare怎么用?PHP DBConnect::prepare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBConnect
的用法示例。
在下文中一共展示了DBConnect::prepare方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ryp_insert
public function ryp_insert($table, $rows = null, $header = null)
{
try {
$sql = "INSERT INTO " . $table;
$row = null;
$value = null;
foreach ($rows as $key => $nilainya) {
# code...
$row .= "," . $key;
$value .= ", :" . $key;
}
$sql .= "(" . substr($row, 1) . ")";
$sql .= "VALUES(" . substr($value, 1) . ")";
$stmt = parent::prepare($sql);
$stmt->execute($rows);
$rowcount = $stmt->rowCount();
if ($rowcount != 0) {
echo "<script> alert('Simpan Data Sukses {$rowcount}');\n\t\twindow.location.assign('{$header}');</script>";
} else {
echo "<script> alert('Simpan Data Error, Data Sudah Ada {$rowcount}'); </script>";
}
if ($header != null) {
//session_start();
//$_SESSION['pesan']="SIMPAN DATA TABEL $table SUKSES";
header("location:" . $header);
}
return $rowcount;
} catch (PDOException $e) {
echo "<script> alert('Simpan Data Gagal'); </script>";
}
}
示例2: CropAndCreate
public function CropAndCreate($fileName, $top, $left, $publicCanvasWidth, $publicCanvasHeight)
{
//set basic variables
//$newFileName is using the set index e.g. [index]jacobclausen_[timestamp]1785645465.jpg
$newFileName = $this->fileNameIndex . time() . '.jpg';
//make sure we actually have a the temporarily uploaded file to work with
if ($fileName != '' && substr($fileName, 0, 3) == 'tmp') {
//even if its unlikely... let's check if we have a file with this exact name since earlier.
if (file_exists($this->outputPath . $newFileName)) {
unlink($this->outputPath . $newFileName);
}
//chmod the file to ensure working conditions with it
chmod($this->tmpPath . $fileName, 0755);
//get the original file dimensions
list($width, $height) = getimagesize($this->tmpPath . $fileName);
//create the canvas
$imageCanvas = imagecreatetruecolor($this->canvasWidth, $this->canvasHeight);
//set the custom background color in case of "white space" in the new image
$backgroundColor = imagecolorallocate($imageCanvas, $this->canvasBG[0], $this->canvasBG[1], $this->canvasBG[2]);
imagefill($imageCanvas, 0, 0, $backgroundColor);
$image = imagecreatefromjpeg($this->tmpPath . $fileName);
//top and left margins accurate
$newTop = $top * ($this->canvasHeight / $publicCanvasHeight);
$newLeft = $left * ($this->canvasWidth / $publicCanvasWidth);
//make adjustments to our image
if ($this->imageCrop == 1) {
imagecopyresampled($imageCanvas, $image, $newLeft, $newTop, 0, 0, $width, $height, $width, $height);
} elseif ($this->imageCrop == 2) {
//calculate the new height and keep the image proportinal
$newHeight = $height * ($this->canvasWidth / $width);
imagecopyresampled($imageCanvas, $image, $newLeft, $newTop, 0, 0, $this->canvasWidth, $newHeight, $width, $height);
} elseif ($this->imageCrop == 3) {
//calculate the new width and keep the image proportinal
$newWidth = $width * ($this->canvasHeight / $height);
imagecopyresampled($imageCanvas, $image, $newLeft, $newTop, 0, 0, $newWidth, $this->canvasHeight, $width, $height);
}
//finally create the image
if (imagejpeg($imageCanvas, $this->outputPath . $newFileName, $this->quality)) {
//check if this image should be added to the database
if ($this->addToDB === true) {
$con = new DBConnect();
try {
$stmt = $con->prepare('INSERT INTO images(image_name) VALUES(?)');
$stmt->execute(array($newFileName));
} catch (PDOException $e) {
$this->output = $e;
}
}
//return the filename
return $newFileName;
//finally remove the temporarily image
unlink($this->tmpPath . $fileName);
}
}
}