ZendFramework::Zend_Db(2)

プレースホルダを利用する

try {

	$dbConfig = new Zend_Config_Int('Config/config.ini', 'database');
	$db = Zend_Db::factory($dbConfig);

	$stt = $db->prepare('INSERT INTO Book(isbn, title, price, publish, pulished) VALUES(:isbn, :title, :price, :pulish, :published)');

	$stt->bindParam(':isbn', $_POST['isbn']);
	$stt->bindParam(':title', $_POST['title']);
	$stt->bindParam(':price', $_POST['price']);
	$stt->bindParam(':publish', $_POST['publish']);
	$stt->bindParam(':published', $_POST['published']);
	※今はセキュリティとかなしで

	$stt->execute();

} catch (Zend_Exception $e) {
	die($e->getMessage());
}

bindParamの代わりに

$stt->execute(array(':isbn' => $_POST['isbn'], ...));

でもいい。

$arr = array(
	':isbn' => '0123456789',
	':title' => 'php book',
	':price' => '980'
	...
	...
);

$stt->execute($arr);

これも一緒。

bindValue()とbindParam()があるけど、ソースを見ると

public function bindValue($parameter, $value, $type = null)
{
    return $this->bindParam($parameter, $value);
}

とかなってて必要なのかよくわからない

Leave a Reply