标题: PHP网页编程之php操作mysql的类! [打印本页] 作者: 萌萌妈妈 时间: 2015-2-3 23:54 标题: PHP网页编程之php操作mysql的类! 学校并没有那么多的时间可以让我们在实际开发上面。mysql <?
# All text and code within this file are (c)opyright
# Pangolin Software Limited 2000.
#
# You may edit this file to customise it for your web-site,
# however, the actual source code may not be altered in
# any way without the prior written permission of Pangolin
# Software Limited.
# This file is part of the Pangolin Vote distribution.
# Contact: pangolin@pango.co.uk or www.pango.co.uk for more info.
/*
* Utility routines for MySQL.
* Modified from code from: http://www.webwizard.com/tutorials/mysql/
*/
class MySQL_class {
# Make sure you fill in the values below for your web-site.
# They are for user,password,host and database respectively.
#
var $user = "USERNAME";
var $pass = "PASSWORD";
var $thedatabase ="DATABASE";
var $host = "localhost";
var $db, $id, $result, $rows, $data, $a_rows;
/*
* It's a minor security hole to have the username and password
* appear here. Generally there isn't any way of getting around it
* if you're using a commercial web hosting service. There are other
* ways if it's your own web server.
*/
function Setup ($user, $pass) {
$this->user = $user;
$this->pass = $pass;
}
function Create () {
$db=$this->thedatabase;
$this->db = $db;
$crash=0;
$this->id = @mysql_pconnect($this->host, $this->user, $this->pass) or
$crash=1;
if ($crash==1) {
MySQL_ErrorMsg("Unable to connect to MySQL server: $this->host - Either your username, password or database values are incorrect in vutil.php3 or you have not started MYSQL on your web server!");
die("<p>Unable to continue.<p>");
}
$this->selectdb($db);
}
function SelectDB ($db) {
$crash=0;
@mysql_select_db($db, $this->id) or $crash=1;
if ($crash==1)
{
MySQL_ErrorMsg ("Unable to select database: $db : The value in vutil.php3 may be incorrect.");
die ("<p>Unable to continue.<p>");
}
}
# Use this function is the query will return multiple rows. Use the Fetch
# routine to loop through those rows.
function Query ($query) {
$this->result = @mysql_query($query, $this->id) or
MySQL_ErrorMsg ("Unable to perform query: $query");
$this->rows = @mysql_num_rows($this->result);
$this->a_rows = @mysql_affected_rows($this->result);
}
# Use this function if the query will only return a
# single data element.
function QueryItem ($query) {
$this->result = @mysql_query($query, $this->id) or
MySQL_ErrorMsg ("Unable to perform query: $query");
$this->rows = @mysql_num_rows($this->result);
$this->a_rows = @mysql_affected_rows($this->result);
$this->data = @mysql_fetch_array($this->result) or MySQL_ErrorMsg ("Unable to fetch.");
return($this->data[0]);
}
# This function is useful if the query will only return a
# single row.
function QueryRow ($query) {
$this->result = @mysql_query($query, $this->id) or
MySQL_ErrorMsg ("Unable to perform query: $query");
$this->rows = @mysql_num_rows($this->result);
$this->a_rows = @mysql_affected_rows($this->result);
$this->data = @mysql_fetch_array($this->result) or MySQL_ErrorMsg ("Unable to fetch.");
return($this->data);
}
function Fetch ($row) {
@mysql_data_seek($this->result, $row) or MySQL_ErrorMsg ("Unable to seek data.");
$this->data = @mysql_fetch_array($this->result) or MySQL_ErrorMsg ("Unable to fetch.");
}
function Insert ($query) {
$this->result = @mysql_query($query, $this->id) or
MySQL_ErrorMsg ("Unable to perform insert: $query");
$this->a_rows = @mysql_affected_rows($this->result);
}
function Update ($query) {
$this->result = @mysql_query($query, $this->id) or
MySQL_ErrorMsg ("Unable to perform update: $query");
$this->a_rows = @mysql_affected_rows($this->result);
}
function Delete ($query) {
$this->result = @mysql_query($query, $this->id) or
MySQL_ErrorMsg ("Unable to perform Delete: $query");
$this->a_rows = @mysql_affected_rows($this->result);
}
}
/* ********************************************************************
* MySQL_ErrorMsg
*
* Print out an MySQL error message
*
*/
function MySQL_ErrorMsg ($msg) {
# Close out a bunch of HTML constructs which might prevent
# the HTML page from displaying the error text.
echo("</ul></dl></ol<\n");
echo("</table></script>\n");
# Display the error message
$text = "<font color=\"#ff0000\"><p><b>Error: $msg :";
$text .= mysql_error();
$text .= "</b></font>\n";
$errormsg=$text;
# get rid of Unable to fetch error messages
if (strpos($errormsg,"Unable to fetch")==false)
print "$errormsg\n";
}
?> 因为函数实在是太多了,慢慢的你就会知道,知道有这个函数就可以。作者: 老尸 时间: 2015-2-4 06:57
Apache不是非得用80或者8080端口的,我刚开始安得时候就是80端口老占用,就用了个 81端口,结果照常,就是输localhost的时候,应该输入为 localhost:81作者: 深爱那片海 时间: 2015-2-6 00:14
使用zendstdio 写代码的的时候,把tab 的缩进设置成4个空格是很有必要的作者: 谁可相欹 时间: 2015-2-14 13:23
其实没啥难的,多练习,练习写程序,真正的实践比看100遍都有用。不过要熟悉引擎作者: 海妖 时间: 2015-2-21 14:39
环境搭建好,当你看见你的浏览器输出“it works\\\\\\\"时你一定是喜悦的。在你解决问题的时候,我强烈建议多读php手册。作者: 分手快乐 时间: 2015-2-28 04:11
说php的话,首先得提一下数组,开始的时候我是最烦数组的,总是被弄的晕头转向,不过后来呢,我觉得数组里php里最强大的存储方法,所以建议新手们要学好数组。作者: 冷月葬花魂 时间: 2015-3-3 15:40
真正的方向了,如果将来要去开发团队,你一定要学好smarty ,phplib这样的模板引擎,作者: 金色的骷髅 时间: 2015-3-11 11:35
,熟悉html,能用div+css,还有javascript,优先考虑linux。我在开始学习的时候,就想把这些知识一起学习,我天真的认为同时学习能够互相呼应,因为知识是相通的。作者: 愤怒的大鸟 时间: 2015-3-16 13:33
刚开始安装php的时候,我图了个省事,把php的扩展全都打开啦(就是把php.ini 那一片 extension 前面的冒号全去掉啦),这样自然有好处,以后不用再需要什么功能再来打开。作者: 再现理想 时间: 2015-3-22 23:10
php是动态网站开发的优秀语言,在学习的时候万万不能冒进。在系统的学习前,我认为不应该只是追求实现某种效果,因为即使你复制他人的代码调试成功,实现了你所期望的效果,你也不了解其中的原理。作者: 兰色精灵 时间: 2015-3-26 21:26
找到的的资料很多都是在论坛里的,需要注册,所以我一般没到一个论坛都注册一个id,所有的id都注册成一样的,这样下次再进来的时候就不用重复注册啦。当然有些论坛的某些资料是需要的付费的。作者: 透明 时间: 2015-3-27 05:09
爱上php,他也会爱上你。作者: 变相怪杰 时间: 2015-4-10 11:43
我要在声明一下:我是个菜鸟!!我对php这门优秀的语言也是知之甚少。但是我要在这里说一下php在网站开发中最常用的几个功能:作者: 乐观 时间: 2015-4-11 02:11
对于懒惰的朋友,我推荐php的集成环境xampp或者是wamp。这两个软件安装方便,使用简单。但是我还是强烈建议自己动手搭建开发环境。作者: 飘飘悠悠 时间: 2015-4-11 05:21
遇到出错的时候,我经常把错误信息直接复制到 google的搜索栏,一般情况都是能搜到结果的,不过有时候会搜出来一大片英文的出来,这时候就得过滤一下,吧中文的弄出来,挨着式方法。作者: 小女巫 时间: 2015-4-11 19:58
环境搭建好,当你看见你的浏览器输出“it works\\\\\\\"时你一定是喜悦的。在你解决问题的时候,我强烈建议多读php手册。作者: admin 时间: 2015-4-22 02:08
至于模板嘛,各位高人一直以来就是争论不休,我一只小菜鸟就不加入战团啦,咱们新手还是多学点东西的好。作者: 活着的死人 时间: 2015-5-4 03:30
最后祝愿,php会给你带来快乐的同时 你也会给他带来快乐。作者: 山那边是海 时间: 2015-6-18 05:01
我还是推荐用firefox ,配上firebug 插件调试js能省下不受时间。谷歌的浏览器最好也不少用,因为谷歌的大侠们实在是太天才啦,把一些原来的js代码加了一些特效。作者: 若相依 时间: 2015-7-8 22:28
环境搭建好,当你看见你的浏览器输出“it works\\\\\\\"时你一定是喜悦的。在你解决问题的时候,我强烈建议多读php手册。作者: 蒙在股里 时间: 2015-7-9 02:32
实践是检验自己会不会的真理。