Home > Backend Development > PHP Tutorial > A database operation class with relatively complete functions_PHP tutorial

A database operation class with relatively complete functions_PHP tutorial

WBOY
Release: 2016-07-13 17:42:45
Original
997 people have browsed it

 

<ol class="dp-c">
<li class="alt"><span><span><?php    </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></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>
Copy after login
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template