写出你的经典代码?给代码有分?

swzlxm 2005-07-01 01:49:11
最近为了做一个PHP网站.
初学PHP.
原来一直用.NET+MSSQL,所以若有MYSQL的经典代码也可以贴出来.

看经典代码才能学得快.

望大家支持,我要一个月内成PHP高手.
...全文
247 13 打赏 收藏 转发到动态 举报
写回复
用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学习网站吗?
  • 打赏
  • 举报
回复
请看这个论坛的FAQ!!
你看完后就绝对是半个高手了。。。
keaizhong 2005-07-01
  • 打赏
  • 举报
回复
blog.csdn.net/kingerq
loveconan 2005-07-01
  • 打赏
  • 举报
回复
<?php
echo ('Hello World!');
?>

不可能有比这个经典的
通过该课程的学习,掌握0行代码写服务框架的服务发布,参数验证,代码生成功能,具备初步的使用能力 该项目本身设计的内容非常多,后期会逐步开放讲解框架后期内容参考:https://mp.csdn.net/editor/html/112142371与Springboot+mybatis和Springboot+jdbctemplate对比:https://editor.csdn.net/md/?articleId=106091083框架主要功能:生成自定义sql模板文件1.一键生成数据库所有列表增、删、改、查接口通过代码生成器,一键生成增、删、改、查代码,分为有代码和无代码两种方式。有代码方式可以在需要业务封装时直接调用生成的代码进行业务组装。有代码方式和无代码方式都可以直接调用访问。2.可指定单表生成接口可以指定生成那张表的数据接口,以免对已有接口造成影响。3.一键生成接口测试postman调用文件生成postman调用接口,直接导入即可测试,不需要单独也写接口文档,也不需要使用swangger在代码中单独增加注释。字段长度类型,大小一目了然。4.可生成controller、service、dao、model、自定义sql、postman测试文件可以根据实际需要进行单独配置5.接口任意参数可自动配置多维度验证比如一个参数phone,在不需要编程的情况下,可以配置验证是否为空、长度、是否是电话号码6.数据接口可以任意组合形成新的接口比如、查询学校是一个接口、查询城市是一个接口,通常情况下在前端是需要两次请求,现在可以通过一次请求自动合并两个接口的数据结果,一次性返回。而这样的组合可以是无限个组合。7.所有接口参数均可自动封装比如查询省份接口,里面有10个参数,前端传入几个参数,便可自动封装几个参数。8.所有查询接口自带分页列表查询,有码方式和无码方式,均自带分页。9.通过简单sql的编辑即可完成服务发布只要会写sql便可生成服务,不需要任何多余操作10.接口可以进行限流配置,可以根据ip、token、ak进行限流操作多维度自定义限流,可设置次数、时限、限流方式11.所有接口可以进行签名认证所有接口通过接口sign签名认证12.所有接口可以进行登录认证限制,也可单独配置不需要登录认证可以指定接口单独授权不需要登录验证,比如验证码接口13.所有接口均可设置需要验证码验证所有的接口都可以通过参数配置设置短信验证码和图片验证码14.所有查询接口均可单独设置缓存所有接口皆可设置单独缓存,缓存周期15.所有接口均可监控访问次数同一接口访问次数记录,很容易监控服务访问,可以做更细致的服务优化16.所有接口均可记录访问日志,包括请求来源请求参数、获得结果入参出参所有访问皆有详细记录17.项目中的代码可以进行自动统计代码量一键统计代码量,包括前后端代码行数和体积18.可以自动进行数据统计,可配置单表数据量统计、也可以配置定时任务数据统计自动表数据统计,方便做BI可视化报表,不需要开发直接配置即可19.可进行跨域设置跨域通过配置文件配置20.可进行IP禁用对于恶意访问ip进行封禁21.可进行访问次数限制所有接口可以进行访问次数限制22.可进行访问来源设备、应用检查验证验证请求来源所用设备和请求发起的应用
不需要开发,0行代码写接口服务,sql编程,只要会sql就会写接口服务,让后端变得更简单,简单4步短短5分钟,立马上手,java小白也可以写接口。订阅课程后可以免费获取发布版进行使用和测试。 0行代码写服务的需要来源案例一,当时有个项目,有400张表,都是管理系统,单表维护的内容较多,当时的项目团队是13人,前后端都写,那时候还没有springboot,用的是ssm,mybatis刚出来,有了替代hibernate的趋势,ifelse写了一堆又一堆,实体类也是,当时的后端分了7层☒,天天加班干这活,复制粘贴,很容易犯错,实体类多人引用修改,真的是废了很大的劲……案例二,也是一个比较大的项目,两千万多万那种,当时为了拿项目,需要快速实现原型给客户看,要求比较高,虽说是原型但是数据全部需要实时,这时候就需要大量编写数据接口,同样编写接口这件事难度倒是不大,但是量大,编写过程手写很容易出错……案例三,以前管理的团队主要做移动端开发,里面的项目会涉及到推送,管理系统,数据采集与同步,总之很多内容,需要前后端通吃,我不仅需要出方案,设计原型,设计数据库,出报价,沟通需求,还要写后端框架,数据接口与数据采集,开发前端(web端),移动端,管理所有项目,但是那时候招的人只会写移动端,实在是忙不过来,我就想能不能有个框架让不会写java的人能写接口,因为写移动端sqlite总是会用的,也就是说写sql不是难点……基于以上三点需求的积累,我利用业余时间写了一个后端框架,完成了这样的需求,刚开始是需要写三行代码完成一个接口,经过后面优化,现在不写代码也可以实现……  本框架涉及的知识点比较多,目前提供最基础版供大家学习和使用,后期逐步推出框架具体的教程和功能内容,下期我们讲如何在实际项目中通过部署版如何完成所需要的接口编写,欢迎大家订阅。

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧