<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ls /proc &#187; zendframework</title>
	<atom:link href="http://www.lsproc.com/blog/tag/zendframework/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.lsproc.com/blog</link>
	<description>lsproc.com</description>
	<lastBuildDate>Fri, 21 May 2010 14:29:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>ZendFramework 使用数据表前缀</title>
		<link>http://www.lsproc.com/blog/use_dbprefix_in_zendframework/</link>
		<comments>http://www.lsproc.com/blog/use_dbprefix_in_zendframework/#comments</comments>
		<pubDate>Thu, 17 Jan 2008 15:07:15 +0000</pubDate>
		<dc:creator>lostsnow</dc:creator>
				<category><![CDATA[Program&Database]]></category>
		<category><![CDATA[dbprefix]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[zendframework]]></category>

		<guid isPermaLink="false">http://www.lostk.com/blog/use_dbprefix_in_zendframework/</guid>
		<description><![CDATA[转载时请标明文章原始出处和作者信息, 作者: lostsnow.http://www.lsproc.com/blog/use_dbprefix_in_zendframework/ 目录结构 在 config.ini 定义 prefix [general] adapter = PDO_MYSQL host = localhost username = root password = 123456 dbname = test charset = utf8 prefix = pf_ //表前缀 index.php 中将 prefix 注册 // 读取数据库配置 $dbconfig = new Zend_Config_Ini(&#039;../config/config.ini&#039;, &#039;general&#039;); // 配置数据库 $database = Zend_Db::factory($dbconfig-&#62;adapter,$dbconfig-&#62;toArray()); // 设置数据库编码 $database-&#62;query(&#34;set names {$dbconfig-&#62;charset};&#34;); Zend_Db_Table::setDefaultAdapter($database); Zend_Registry::set(&#039;database&#039;,$database); // [...]]]></description>
			<content:encoded><![CDATA[<p>转载时请标明文章原始出处和作者信息, 作者: <a href="http://www.lsproc.com/blog/">lostsnow</a>.<br /><a href="http://www.lsproc.com/blog/use_dbprefix_in_zendframework/">http://www.lsproc.com/blog/use_dbprefix_in_zendframework/</a></p>
<p>目录结构<br />
<img src="http://www.lsproc.com/blog/wp-content/uploads/2008/01/zfstruc.png" width="166" height="360" alt="zend framework dirs" title="zend framework dirs" /></p>
<p>在 config.ini 定义 prefix</p>
<pre class="brush: php">[general]
adapter  = PDO_MYSQL
host     = localhost
username = root
password = 123456
dbname   = test
charset  = utf8
prefix   = pf_    //表前缀</pre>
<p>index.php 中将 prefix 注册</p>
<pre class="brush: php">// 读取数据库配置
$dbconfig = new Zend_Config_Ini(&#039;../config/config.ini&#039;, &#039;general&#039;);
// 配置数据库
$database = Zend_Db::factory($dbconfig-&gt;adapter,$dbconfig-&gt;toArray());
// 设置数据库编码
$database-&gt;query(&quot;set names {$dbconfig-&gt;charset};&quot;);
Zend_Db_Table::setDefaultAdapter($database);
Zend_Registry::set(&#039;database&#039;,$database);
// 数据表前缀
Zend_Registry::set(&#039;dbprefix&#039;,$dbconfig-&gt;prefix);</pre>
<p>在 library/Custom 目录下新建文件 Db.php 继承 Zend_Db_Table 类</p>
<pre class="brush: php">class Custom_Db extends Zend_Db_Table
{
    public function __construct()
    {
        $dbprefix = Zend_Registry::get(&#039;dbprefix&#039;);
        $this-&gt;_name = $dbprefix.$this-&gt;_name;
        parent::__construct();
    }
}</pre>
<p>最后在 model 中继承 Custom_Db 即可</p>
<pre class="brush: php">class User extends Custom_Db
{
    protected $_name = &#039;users&#039;;     //在Custom_Db中会自动加上表名的前缀
    protected $_primary = &#039;userid&#039;; //主键
}</pre>
<p>-- EOF --</p>
<h3  class="related_post_title">Related Posts</h3><ul class="related_post"><li>2010-05-21 -- <a href="http://www.lsproc.com/blog/nginx_php_pathinfo_securit/" title="Nginx/PHP 文件类型错误解析漏洞：fix_pathinfo">Nginx/PHP 文件类型错误解析漏洞：fix_pathinfo</a> (2)</li><li>2010-04-12 -- <a href="http://www.lsproc.com/blog/nginx_userid_decode/" title="nginx userid 模块客户端 cookie 解码">nginx userid 模块客户端 cookie 解码</a> (0)</li><li>2010-03-08 -- <a href="http://www.lsproc.com/blog/use_ob_flush_on_nginx_fastcgi/" title="nginx+factcgi 下使用 ob_flush">nginx+factcgi 下使用 ob_flush</a> (0)</li><li>2008-06-15 -- <a href="http://www.lsproc.com/blog/lighttpd_phpfastcgi_config/" title="lighttpd + PHP(fastcgi) 配置">lighttpd + PHP(fastcgi) 配置</a> (0)</li><li>2008-03-18 -- <a href="http://www.lsproc.com/blog/configure_lamp/" title="lamp 相关配置 [Debian]">lamp 相关配置 [Debian]</a> (2)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.lsproc.com/blog/use_dbprefix_in_zendframework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
