一个功能还算完整的数据库操作类_PHP教程

WBOY
發布: 2016-07-13 17:42:45
原創
959 人瀏覽過

 

<ol class="dp-c">
<li class="alt"><span><span><?php     </span></span></span></li>
<li>
<span class="comment">/*  </span> </li>
<li class="alt"><span><span class="comment">*   Author  墨龙  </span> </span></li>
<li><span><span class="comment">*   Time    2010年12月2日 15:50:35   </span> </span></li>
<li class="alt"><span><span class="comment">*/</span><span>    </span></span></li>
<li><span>    </span></li>
<li class="alt">
<span class="vars">$db</span><span> = </span><span class="keyword">new</span><span> mysql(</span><span class="vars">$db_host</span><span>,</span><span class="vars">$db_user</span><span>,</span><span class="vars">$db_password</span><span>,</span><span class="vars">$db_table</span><span>,</span><span class="vars">$db_conn</span><span>,</span><span class="vars">$pre</span><span>,</span><span class="vars">$coding</span><span>);    </span>
</li>
<li><span>    </span></li>
<li class="alt">
<span class="keyword">class</span><span> mysql{    </span>
</li>
<li><span>        </span></li>
<li class="alt">
<span>    </span><span class="keyword">private</span><span>    </span><span class="vars">$db_host</span><span>;    </span>
</li>
<li>
<span>    </span><span class="keyword">private</span><span>    </span><span class="vars">$db_user</span><span>;    </span>
</li>
<li class="alt">
<span>    </span><span class="keyword">private</span><span>    </span><span class="vars">$db_password</span><span>;    </span>
</li>
<li>
<span>    </span><span class="keyword">private</span><span>    </span><span class="vars">$db_table</span><span>;    </span>
</li>
<li class="alt">
<span>    </span><span class="keyword">private</span><span>    </span><span class="vars">$db_conn</span><span>;           </span><span class="comment">//数据库连接标识;   </span><span> </span>
</li>
<li>
<span>    </span><span class="keyword">private</span><span>    </span><span class="vars">$result</span><span>;         </span><span class="comment">//执行query命令的结果资源标识   </span><span> </span>
</li>
<li class="alt">
<span>    </span><span class="keyword">private</span><span>    </span><span class="vars">$sql</span><span>;      </span><span class="comment">//sql执行语句   </span><span> </span>
</li>
<li>
<span>    </span><span class="keyword">private</span><span>    </span><span class="vars">$pre</span><span>;      </span><span class="comment">//数据库表前缀     </span><span> </span>
</li>
<li class="alt">
<span>    </span><span class="keyword">private</span><span>    </span><span class="vars">$coding</span><span>;  </span><span class="comment">//数据库编码,GBK,UTF8,gb2312   </span><span> </span>
</li>
<li><span>        </span></li>
<li class="alt"><span>        </span></li>
<li>
<span>    </span><span class="keyword">function</span><span> __construct(</span><span class="vars">$db_host</span><span>,</span><span class="vars">$db_user</span><span>,</span><span class="vars">$db_password</span><span>,</span><span class="vars">$db_table</span><span>,</span><span class="vars">$db_conn</span><span>,</span><span class="vars">$pre</span><span>,</span><span class="vars">$coding</span><span>){    </span>
</li>
<li class="alt"><span>            </span></li>
<li>
<span>        </span><span class="vars">$this</span><span>->db_host     = </span><span class="vars">$db_host</span><span>;    </span>
</li>
<li class="alt">
<span>        </span><span class="vars">$this</span><span>->db_user     = </span><span class="vars">$db_user</span><span>;    </span>
</li>
<li>
<span>        </span><span class="vars">$this</span><span>->db_password = </span><span class="vars">$db_password</span><span>;    </span>
</li>
<li class="alt">
<span>        </span><span class="vars">$this</span><span>->db_table    = </span><span class="vars">$db_table</span><span>;    </span>
</li>
<li>
<span>        </span><span class="vars">$this</span><span>->db_conn     = </span><span class="vars">$db_conn</span><span>;    </span>
</li>
<li class="alt">
<span>        </span><span class="vars">$this</span><span>->pre         = </span><span class="vars">$pre</span><span>;    </span>
</li>
<li>
<span>        </span><span class="vars">$this</span><span>->coding      = </span><span class="vars">$coding</span><span>;    </span>
</li>
<li class="alt">
<span>        </span><span class="vars">$this</span><span>->connect();    </span>
</li>
<li><span>        </span></li>
<li class="alt"><span>    }    </span></li>
<li><span>        </span></li>
<li class="alt">
<span>    </span><span class="keyword">function</span><span> connect(){    </span>
</li>
<li><span>            </span></li>
<li class="alt">
<span>        </span><span class="vars">$this</span><span>->db_conn = @mysql_connect(</span><span class="vars">$this</span><span>->db_host,</span><span class="vars">$this</span><span>->db_user,</span><span class="vars">$this</span><span>->db_password) </span><span class="keyword">or</span><span> </span><span class="keyword">die</span><span>(</span><span class="vars">$this</span><span>->show_error(</span><span class="string">"数据库链接错误,请检查数据库链接配置!"</span><span>));    </span>
</li>
<li>
<span>        </span><span class="keyword">if</span><span>(!mysql_select_db(</span><span class="vars">$this</span><span>->db_table,</span><span class="vars">$this</span><span>->db_conn)){    </span>
</li>
<li class="alt"><span>                </span></li>
<li>
<span>            </span><span class="func">echo</span><span> </span><span class="string">"没有找到数据表:"</span><span>.</span><span class="vars">$this</span><span>->db_table;    </span>
</li>
<li class="alt"><span>        }    </span></li>
<li>
<span>        mysql_select_db(</span><span class="vars">$this</span><span>->db_t						
<p align="left"></p>
<div style="display:none;">
<span id="url" itemprop="url">http://www.bkjia.com/PHPjc/486033.html</span><span id="indexUrl" itemprop="indexUrl">www.bkjia.com</span><span id="isOriginal" itemprop="isOriginal">true</span><span id="isBasedOnUrl" itemprop="isBasedOnUrl">http://www.bkjia.com/PHPjc/486033.html</span><span id="genre" itemprop="genre">TechArticle</span><span id="description" itemprop="description">?php /* *Author墨龙 *Time2010年12月2日15:50:35 */ $db = new mysql( $db_host , $db_user , $db_password , $db_table , $db_conn , $pre , $coding ); class mysql{ private $db_host...</span>
</div>
<div class="art_confoot"></div>
</span>
</li>
</ol>
登入後複製
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板