http://wiki.nonip.net/index.php?title=Php/zend_framework/DB%E3%83%A1%E3%83%A2&feed=atom&action=history
Php/zend framework/DBメモ - 変更履歴
2024-03-29T11:34:54Z
このウィキのこのページに関する変更履歴
MediaWiki 1.24.2
http://wiki.nonip.net/index.php?title=Php/zend_framework/DB%E3%83%A1%E3%83%A2&diff=1828&oldid=prev
2016年1月9日 (土) 03:12にAdminによる
2016-01-09T03:12:37Z
<p></p>
<table class='diff diff-contentalign-left'>
<col class='diff-marker' />
<col class='diff-content' />
<col class='diff-marker' />
<col class='diff-content' />
<tr style='vertical-align: top;'>
<td colspan='2' style="background-color: white; color:black; text-align: center;">←前の版</td>
<td colspan='2' style="background-color: white; color:black; text-align: center;">2016年1月9日 (土) 03:12時点における版</td>
</tr><tr><td colspan="2" class="diff-lineno">行109:</td>
<td colspan="2" class="diff-lineno">行109:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>         }</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>         }</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>     }</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>     }</div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> }</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">==ステートメントホルダからfetch==</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> $stmt = $db->query('SELECT * FROM bugs');</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"> while ($row = $stmt->fetch()) {</ins></div></td></tr>
<tr><td colspan="2"> </td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">    echo $row['bug_description'];</ins></div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>  }</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>  }</div></td></tr>
</table>
Admin
http://wiki.nonip.net/index.php?title=Php/zend_framework/DB%E3%83%A1%E3%83%A2&diff=920&oldid=prev
127.0.0.1: ページの作成:「==DB接続== $this->db = Zend_Db::factory('Pdo_Mysql', array( 'host' => 'localhost', 'username' => 'usertest', 'password' => '...」
2015-05-19T18:19:08Z
<p>ページの作成:「==DB接続== $this->db = Zend_Db::factory('Pdo_Mysql', array( 'host' => 'localhost', 'username' => 'usertest', 'password' => '...」</p>
<p><b>新規ページ</b></p><div>==DB接続==<br />
$this->db = Zend_Db::factory('Pdo_Mysql', array(<br />
'host' => 'localhost',<br />
'username' => 'usertest',<br />
'password' => 'password',<br />
'dbname' => 'test',<br />
'charset' => 'utf8',<br />
'port' => '3306'<br />
));<br />
$sql = "SELECT * FROM test";<br />
$rows = $this->db->fetchAll($sql);<br />
<br />
*DB接続エラー修正 <br />
trying to connect via unix:///var/mysql/mysql.sock<br />
- 'host' => 'localhost',<br />
+ 'host' => '127.0.0.1',<br />
<br />
==oracleだと・・==<br />
Zend_Db::factory('Pdo_Oci'<br />
<br />
===DBのquote===<br />
$this->db->quote($_POST['test']);<br />
<br />
==外部dbのiniを使用==<br />
//Zend_Configコンポーネントの呼び出し<br />
require_once 'Zend/Config/Ini.php';<br />
//Zend_Dbコンポーネントの呼び出し<br />
require_once 'Zend/Db.php';<br />
//外部ファイルdb.iniをロードしZend_Configオブジェクトを生成<br />
$config = new Zend_Config_Ini('../../../../zendapps/db/db.ini','production');<br />
//Zend_Configオブジェクトを使って、アダプタクラスを生成<br />
$db = Zend_Db::factory($config->default);<br />
db.ini<br />
[production]<br />
default.adapter = Pdo_Mysql<br />
default.params.host = localhost<br />
default.params.dbname = db_zend<br />
default.params.username = xxxxx<br />
default.params.password = xxxxxxxx<br />
default.params.charset = UTF8<br />
default.params.port = 3306<br />
<br />
==bootstrap使用==<br />
bootstrap.phpに以下を追記<br />
protected function _initDb()<br />
{<br />
//外部ファイルdb.iniをロードしZend_Configオブジェクトを生成<br />
$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini',APPLICATION_ENV);<br />
//Zend_Configオブジェクトを使って、アダプタクラスを生成<br />
$db = Zend_Db::factory($config->default);<br />
// $db->query("set names utf8");<br />
Zend_Db_Table::setDefaultAdapter($db);<br />
}<br />
<br />
==プレースホルダ==<br />
$sql = 'INSERT INTO users(name, age) values(?, ?);';<br />
$db->query($sql, array('taro', 10));<br />
<br />
==sqlログを取る==<br />
注:プレースホルダーとバインド値は個別に出力<br />
*action.php<br />
$db = CustomDb::factory();<br />
$db->query($sql);<br />
<br />
*CustomDb.php<br />
<?php<br />
require_once 'Zend/Db.php';<br />
class CustomDb extends Zend_Db<br />
{<br />
private $_db;<br />
private function __construct($adapter, $config = array())<br />
{<br />
$this->_db = Zend_Db::factory($adapter, $config);<br />
// プロファイルを有効に<br />
$this->_db->getProfiler()->setEnabled(true);<br />
}<br />
public static function factory($adapter, $config = array())<br />
{<br />
$class = __CLASS__;<br />
$instance = new $class($adapter, $config);<br />
return $instance;<br />
}<br />
public function __call($name, array $args)<br />
{<br />
switch ($name) {<br />
case 'fetchAll':<br />
case 'fetchRow':<br />
case 'fetchAssoc':<br />
case 'fetchCol':<br />
case 'fetchOne':<br />
case 'prepare':<br />
case 'query':<br />
case 'exec':<br />
require_once 'Zend/Log.php';<br />
$log = new Zend_Log();<br />
require_once 'Zend/Log/Writer/Stream.php';<br />
$log->addWriter(new Zend_Log_Writer_Stream('/tmp/sql.log'));<br />
try {<br />
$buf = call_user_func_array(array($this->_db, $name), $args);<br />
$query = $this->_db->getProfiler()->getLastQueryProfile();<br />
$log->log(sprintf("%s [%s] %ss", $query->getQuery(), join(",", $query->getQueryParams()), $query->getElapsedSecs()), Zend_Log::DEBUG);<br />
} catch (Exception $e) {<br />
$query = $this->_db->getProfiler()->getLastQueryProfile();<br />
$log->log(sprintf("%s [%s]", $query->getQuery(), join(",", $query->getQueryParams())), Zend_Log::ERR);<br />
}<br />
return $buf;<br />
default:<br />
return call_user_func_array(array($this->_db, $name), $args);<br />
}<br />
}<br />
}</div>
127.0.0.1