社区
基础编程
帖子详情
写出你的经典代码?给代码有分?
swzlxm
2005-07-01 01:49:11
最近为了做一个PHP网站.
初学PHP.
原来一直用.NET+MSSQL,所以若有MYSQL的经典代码也可以贴出来.
看经典代码才能学得快.
望大家支持,我要一个月内成PHP高手.
...全文
275
13
打赏
收藏
写出你的经典代码?给代码有分?
最近为了做一个PHP网站. 初学PHP. 原来一直用.NET+MSSQL,所以若有MYSQL的经典代码也可以贴出来. 看经典代码才能学得快. 望大家支持,我要一个月内成PHP高手.
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
13 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
swzlxm
2005-07-04
打赏
举报
回复
上周末在圖書館轉了一下,翻了幾本PHP的書,發現沒什麽東西
看來都是要經驗的
ray929
2005-07-02
打赏
举报
回复
一本php手册顶半边天
另外半边就是自己的经验了
创造奇迹9999
2005-07-02
打赏
举报
回复
关注!!!
phpsessid
2005-07-02
打赏
举报
回复
page.class.php
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
// +----------------------------------------------------------------------+
// | PHP Version 5 |
// +----------------------------------------------------------------------+
// | Copyright (c) surreyk@msn.com(风随影动) |
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Author: 风随影动<surreyk@msn.com> |
// | |
// +----------------------------------------------------------------------+
//
// $Id: page.class.php,v 2.0 2005/03/19 22:07:11 Exp $
class page {
//$_GET
private $Gar = array();
//$_POST
private $Par = array();
//constractor function
public function _construct() {
die ("<!-- 这个类不能被实例化 -->程序遇到一个致命异常,已经被关闭");
}
//解析替换特殊字符 单引号' 双引号" 反斜线 \
private function parse($values)
{
if (is_Array($values)) {
for (reset($values); $key = key($values); next($values)) {
$values[$key] = str_replace("'", "\'", $values[$key]);
$values[$key] = str_replace("\\", "", $values[$key]);
$values[$key] = str_replace('"', "", $values[$key]);
$values[$key] = str_replace('_', "", $values[$key]);
}
} else {
$values = str_replace("'", "\'", $values);
$values = str_replace("\\", "\\\\", $values);
$values = str_replace('"', "\"", $values);
$values = str_replace('_', "", $values);
}
return $values;
}
//获取安全的GET参数
public function safeGet($var = false)
{
if ($var) {
$var = $_GET[$var];
return trim(page::parse($var));
} else {
return page::parse($_GET);
}
}
//获取安全的POST参数
public function safePost($var = false)
{
if ($var) {
$var = $_POST[$var];
return trim(page::parse($var));
} else {
return page::parse($_POST);
}
}
//获取$_SERVER数组
public function Sear($var = false)
{
if ($var) {
return $_SERVER[$var];
} else {
return $_SERVER;
}
}
function showErrorPage($msg)
{
die($msg);
}
}
?>
phpsessid
2005-07-02
打赏
举报
回复
config.cfg.php
<?php
$DBhost = "localhost";
$DBuser = "root";
$DBpass = "";
$DBbase = "fsyd_homepage";
$DSN = "mysql://".$DBuser.":".$DBpass."@".$DBhost."/".$DBbase;
$vars = array();
$programDir = dirname($_SERVER['PHP_SELF']);
$vars['programDir'] = substr($programDir, 1, strlen($programDir));
$vars['systemName'] = "";
?>
phpsessid
2005-07-02
打赏
举报
回复
经典代码?
<?php
include_once 'exception/exception.class.php';
include_once 'phplib_template.class.php';
include_once 'PEAR/DB.php';
include_once 'config.cfg.php';
include_once 'page.class.php';
class manage
{
protected $tpl;
protected $DB;
/**
* Construct function,to Init templateClass and Database connect
*/
public function __construct($DSN)
{
try {
$this->cacheTPL = new cacheTemplate("template/admin_template", "remove");
$this->tpl = new Template("template/admin_template", "remove");
} catch (templateException $tplex) {
print $tplex->getMessage();
exit;
}
$this->DB = DB::connect($DSN);
if (DB::isError($this->DB)) {
print $this->DB->getMessage();
exit;
}
return true;
}
}
class categoryManage extends manage
{
/**
* Construct function,to Init templateClass and Database connect
*/
public function __construct($DSN)
{
parent::__construct($DSN);
}
/**
* Control method >> show the category add page
*/
public function showAddForm($vars = array(), $tplFile = "category_showAddForm.html")
{
if ($this->cacheTPL->isCached("category_showaddform")) {
$this->cacheTPL->printCache("category_showaddform");
exit;
}
try {
$this->cacheTPL->setFile("showAddForm", $tplFile, "category_showaddform");
if (count($vars) != 0) {
$this->cacheTPL->setVar($vars);
}
$this->cacheTPL->setBlock("showAddForm", "pcSelectList", "pcSelectLists");
$queryRes = $this->DB->query("select `name`,`ID` from contentcategory");
if (DB::isError($queryRes)) {
echo "<p>" .$queryRes->getMessage()."</p><p>数据库错误</p>";
exit;
}
while($res = $queryRes->fetchRow()) {
$this->cacheTPL->setVar("categoryName", $res[0]);
$this->cacheTPL->setVar("categoryID", $res[1]);
$this->cacheTPL->parse("pcSelectLists", "pcSelectList", true);
}
$this->cacheTPL->setBlock("showAddForm", "tplSelectList", "tplSelectLists");
$queryRes = $this->DB->query("select `name`,`ID` from `template`");
if (DB::isError($queryRes)) {
echo "<p>" .$queryRes->getMessage()."</p><p>数据库错误</p>";
exit;
}
while($res = $queryRes->fetchRow()) {
$this->cacheTPL->setVar("templateName", $res[0]);
$this->cacheTPL->setVar("templateID", $res[1]);
$this->cacheTPL->parse("tplSelectLists", "tplSelectList", true);
}
$this->cacheTPL->pparse("showAddForms", "showAddForm");
} catch (templateException $tplex) {
print $tplex->getMessage();
exit;
}
return true;
}
public function showListMain($vars = array(), $tplFile = "category_showListMain.html")
{
if ($this->cacheTPL->isCached("category_showlistmain")) {
$this->cacheTPL->printCache("category_showlistmain");
exit;
}
try {
$this->cacheTPL->setFile("showListMain", $tplFile, "category_showlistmain");
if (count($vars) != 0) {
$this->cacheTPL->setVar($vars);
}
$this->cacheTPL->setBlock("showListMain", "list", "lists");
$queryRes = $this->DB->query("select * from `contentCategory`");
while ($res = $queryRes->fetchRow()) {
$this->cacheTPL->setVar("name", $res[0]);
$this->cacheTPL->setVar("type", $res[1]);
if ($res[3] == 0) {
$this->cacheTPL->setVar("parent", '无');
}
$this->cacheTPL->setVar("tplname", $res[6]);
$this->cacheTPL->setVar("caption", $res[4]);
$this->cacheTPL->setVar("description", $res[5]);
$this->cacheTPL->setVar("id", $res[7]);
$this->cacheTPL->setVar("display", $res[2] == 1? '是': '否');
$this->cacheTPL->setVar("", $res[]);
$this->cacheTPL->parse("lists", "list", true);
}
$this->cacheTPL->pparse("showListMains", "showListMain");
} catch (templateException $tplex) {
print $tplex->getMessage();
exit;
} catch (DBException $DBex) {
print $DBex->getMessage();
exit;
}
return true;
}
public function addNewCategory()
{
if (page::safePost('type') == "") {
$type = "artical";
} else {
$type = page::safePost('type');
}
if (page::safePost('topCategory') == 1) {
$parentID = 0;
$topCategory = 1;
} else {
$topCategory = 0;
}
if (page::safePost('parentCategory') == 'null') {
$topCategory = 1;
$parentID = 0;
} else {
$parentID = page::safePost('parentCategory');
}
if (page::safePost('className') == "") {
die("<script>alert('请输入分类名称');history.back(1);</script>");
} else {
$className = page::safePost('className');
}
if (page::safePost('classIntroduce') == "") {
$classIntroduce = "";
} else {
$classIntroduce = page::safePost('classIntroduce');
}
if (page::safePost('tplSelect') == "") {
die("<script>alert('请选择一个模板');history.back(1);</script>");
} else {
$tplid = page::safePost('tplSelect');
}
$showIntroduceOnPage = (int)page::safePost('showIntroduceOnPage');
try{
$this->DB->query("select * from `contentCategory` where `name`='$className' and `type`='$type' and `parentID` = '$parentID'");
if ($this->DB->affectedRows() != 0) {
die("<script>alert('已经存在一个同名、同父类的分类');history.back(1);</script>");
}
$this->DB->query("insert into `contentCategory` values('$className','$type', '$showIntroduceOnPage', '$parentID', '$classIntroduce', '', '$tplid', '')");
echo "<script>alert('类别".$className."添加成功');window.href='manage.php?class=categoryManage&method=showListMain';</script>";
} catch(DBException $DBex) {
print $DBex->getMessage();
exit;
}
$this->cacheTPL->refresh('showlistmain');
return true;
}
/*
public function delete()
{
if (page::safeGet('id') == "" or strlen(page::safeGet('id')) > 2) {
$parmeterE = new parmeterException("参数ID非法,请不要手动指定ID", 40000);
die(@header("location:error.php?e=".$parmeterE->getCode()));
}
if (page::safeGet('step') != 2) {
try {
$this->tpl->setFile("saveMethod", "category_delete_selectsavemethod.html");
$queryRes = $this->DB->query("select * from `contentCategory` where id='".page::safeGet('id')."'");
} catch (DBException $DBe) {
print $DBe->getMessage();
exit;
} catch (templateException $tple) {
print $tple->getMessage();
exit;
}
}
}*/
}
class contentManage extends manage
{
public function __construct($DSN)
{
parent::__construct($DSN);
}
public function showAddCategory($vars = array(), $tplFile = "content")
{
if ($this->cacheTPL->isCached("content_showaddcategory")) {
$this->cacheTPL->printCache("content_showaddcategory");
exit;
}
$this->cacheTemplate->setFile("content_showAddCategory", $tplFile, "content_showaddcategory");
$this->cacheTemplate->setVar($vars);
}
public function showAddForm($vars = array(), $tplFile = "content")
{
if ($this->cacheTPL->isCached("content_showaddform")) {
$this->cacheTPL->printCache("content_showaddform");
exit;
}
$this->cacheTemplate->setFile("showAddForm", $tplFile, "content_showaddform");
$this->cacheTemplate->setVar($vars);
}
}
?>
调用
<?php
include_once 'inc/global_session_check.php';
include_once 'inc/manage.class.php';
include_once 'inc/phplib_template.class.php';
if ($_GET['class'] == "" || $_GET['method'] == "") {
} else {
$classInstence = new $_GET['class']($DSN);
$classInstence->$_GET['method']($vars);
}
?>
Meteorlet
2005-07-02
打赏
举报
回复
www.php.net
hope1983
2005-07-01
打赏
举报
回复
www.google.com
www.phpx.com/happy/
www.phpe.net
forlish
2005-07-01
打赏
举报
回复
php官方手册,不错的资料。
swzlxm
2005-07-01
打赏
举报
回复
我想要的是经典PHP代码.
像JAVASCRIPT就不用了.
另外:有官方资源网站吗?(像MSDN这样的)
有比较好的PHP学习网站吗?
山雨欲来-风满楼
2005-07-01
打赏
举报
回复
请看这个论坛的FAQ!!
你看完后就绝对是半个高手了。。。
keaizhong
2005-07-01
打赏
举报
回复
blog.csdn.net/kingerq
loveconan
2005-07-01
打赏
举报
回复
<?php
echo ('Hello World!');
?>
不可能有比这个经典的
三年JavaEE开发积累的那些
代码
之一:JavaSE篇完整实例源码
三年JavaEE开发积累的那些
代码
之一:JavaSE篇 有什么? 1)自己写的例子:或是为了项目中应用写的demo,或是为了学习某项技术写的demo。 2)网上下载的例子:或改过或没改过,或完善过或原封没动。 没什么? 1)公司项目的源
代码
(这个真没有,虽然可以有,虽然已经离职2年有余) 以后若有时间,可以将项目源
代码
中的某些技术(并不是什么高深的技术)提炼出 来发帖子或博客,分享之。 2)公司业务紧密相关的测试
代码
。
SQLServer_2000-2008_R2查询智能分析器RedGate_SQL_Prompt_V5.3.4.1_Crack_Keygen破解教程注册机免费
SQL脚本越写越多,总是觉得编写效率太过于低下,这和打字速度无关。在我个人编写SQL脚本时,至少会把SQL的格式排列成易于阅读的,因为其他人会阅读到你的SQL,无论是在程序中或是脚本文件中,良好的排版不仅让人看起来赏心悦目,在和他人之间做交流时也省时省力,不会因为揉成一团的sql去询问Team Member:您能帮我解释一下这么一大段sql是做什么的吗? 虽然微软至SQL 2008以上的版本提供了SQL智能提示,但是它的反应实在是过于迟钝,等提示出来我们早就可以敲出一行语句了。而且它没有提供sql
代码
格式化的功能,咱们只能自己做手动格式化,手动格式化sql总是需要花费不少时间的。 它也是一款拥有智能提示的sql编程工具,而且小巧灵活。 总而言之,它也是一款能够提高sql编程效率的工具。 注释:内附破解教程doc。和keygen,欢迎免费下载
如何
写出
健壮和优雅的
代码
?
阿里妹导读:关于
代码
的健壮性,其重要性不言而喻。那么如何才能
写出
健壮的
代码
?阿里文娱技术专家长统将从防御式编程、如何正确使用异常和 DRY 原则等三个方面,并结合
代码
实例,分享自己的看法心得,希望对同学们有所启发。 你不可能
写出
完美的软件。因为它不曾出现,也不会出现。 每一个司机都认为自己是最好的司机,我们在鄙视那些闯红灯、乱停车、胡乱变道不遵守规则的司机同时,更应该在行驶的过程中防卫性的驾驶,小心那些突然冲出来的车辆,在他们给我们造成麻烦的时候避开他。这跟编程有极高的相似性,我们在程序...
你写过的最蠢的
代码
是?
猫头虎博主在此分享一下,每个程序员在编程道路上都会有一些让自己感到啼笑皆非的
代码
经历。特别是在刚开始学习编写
代码
的时候,往往会
写出
一些现在看来非常愚蠢的
代码
。这些“愚蠢”的
代码
往往是我们成长的见证,也是我们进步的阶梯。通过本文,我们将会回顾并分析一些常见的编程错误和不良实践,同时也会探讨如何通过持续学习和实践,避免这些错误,成为一个更优秀的程序员。“编程新手错误”、"
代码
优化"和"编程最佳实践"是非常热门的话题,我们也将围绕这些话题展开讨论。每个程序员都有可能
写出
“愚蠢”的
代码
,重要的是要从中学习和成长。
代码
如何编写?
编写
代码
需要使用一种编程语言,并使用文本编辑器或集成开发环境(IDE)将
代码
编写到文件中。 通常,在编写
代码
时,你需要遵循一些基本规则: 每种编程语言都有自己的语法,这些语法规定了如何构造程序以及如何表达各种操作。例如,在 Python 中,你可以使用 print() 函数来输出文本。
代码
通常包含若干个函数,每个函数都有特定的功能。你可以通过调用函数来执行特定的任务。
代码
中的变量可以存储...
基础编程
21,890
社区成员
140,338
社区内容
发帖
与我相关
我的任务
基础编程
从PHP安装配置,PHP入门,PHP基础到PHP应用
复制链接
扫一扫
分享
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章