易栈网-膘叔

发文热力图 2025-12-07 ~ 2026-12-06
少 多 近 365 天共 27 篇
浏览模式: 标准 | 列表 | 图文
主键和外键的设计原则

主键和外键的设计原则

从MYSQL4.1开始,它终于支持了外键。在数据库设计中,主键和外键是一种能够把多个表组织为一个有效的关系数据库的粘合剂。它们的设计良好与否对数据库的性能和可用性有着决定性的影响。

不得不说的是,在系统设计的时候,必须将数据库模式从理论上的逻辑设计转换为实际的物理设计。而主键和外键的结构是这个设计过程的症结所在。毕竟,一旦将所设计的数据库用于了生产环境,就很难对他们进行修改,因此,在开发阶段设计好主键和外键就显得犹为重要。

对于主键而言,它是不可被重复的,而且尽量不包含特殊含义,毕竟主键的使用只是为了让数据库多一条高效的索引,而且在被外部引用的时候不会产生重复。同样重要的是主键最好不要和其他键一起组成复合主键,而应该单独用一列来表示。

正因为主键的特殊性,所以在大多数情况下我们都采用了自增字段来表示(但由于前台应用的特殊性,建议在表字段中增加一列有唯一约束的字段,用作前台显示用。比如,原来查看新闻可能是:news.php?newsId=123,这样别人很容易猜出下一条是124,前一条是122,平时这样使用是无所谓,但如果是使用在订单上,别人就很容易知道你的订单数量等,如果采用了GUID这样的值,虽然看起来复杂了一点,但永远不会被人猜出你的订单)

当然主键也可以使用这种GUID来进行设定,但确实是不太建议使用,我主要是指MYSQL,因为MYSQL默认没有默认生成这样键值的函数。而且使用定长字符串做主键,在被外部引用的时候,就显得太长了。

而外键就相对来说比主键约束要小的多,但也是有一定规范的。比如,用主键作外键,这是大多数人的用法。即使在MYSQL尚未支持外键的时候,大多数情况下。也都是通过这样的方式来进行关联。

在使用外键的时候,一般建议是不要超过4张表关联,超过4张,可能你在某些个表里就纯粹看到的是ID记录(类似于数据库的索引),这个时候麻烦的问题就来了。该如何维护这样一个全是ID记录的表呢?一旦这个表被人误操作了。那么。所有的数据都将失去关联了。(如果数据库支持外键功能,在删除这样的外键关联数据,我记得是会出错的。)

外键,除了使用主键外,还有就是那种具有唯一索引的列,仔细想想也确实这样,如果没有唯一,那么关联出来的数据怎么能够具有唯一性?

利用外键进行数据的更新删除,应该是最方便的了。这样也可以避免数据库里会存在冗余数据。

——END——

纯粹是在这里发发牢骚,真正的表设计不是这么简单的。还要根据实际的应用,但这些可以算是一些小小的经验。也许在真正的高手眼里这些都不值一提。但,千里马常有,而伯乐不常有啊。很多人都认为是理所当然的事情,不代表我们这些新手就明白。

记录下来,作为参考,也算是一个笔记

恭喜一下,phpmyadmin出了3.0测试版

恭喜一下,phpmyadmin出了3.0测试版

看新闻的时候,突然看到phpmyadmin出了3.0beta版本,只是好象新版本是基于5.2开发的。源码地址为:http://internap.dl.sourceforge.net/sourceforge/phpmyadmin/phpMyAdmin-3.0.0-beta-all-languages.zip,大家可以去下载,如果不能下载,可以先到:http://sourceforge.net/projects/phpmyadmin/,找到3.0beta版进行下载。

对于使用PHP进行开发的人员来说,phpmyadmin可以说是最常用的工具之一。其重要性不亚于一个好的IDE所带来的功效。

SF上面如此提示:

Welcome to the beta release of phpMyAdmin 3.0.0. This version supports various features of MySQL 5.1, the Maria and PBXT storage engines and
SweKey hardware authentication. The 3.0 series requires PHP 5.2+ and MySQL 5.0+.

看到cnbeta上有人评价说:phpmyadmin不是利器,而是神器。心中亦有此感啊。

下载源码,学习一下。oh yeah

Delphi2009重出江湖

虽然我至今为止还不能熟练使用delphi,但不代表我就不关心他。这不,我看到了最新的消息,马上就公布于众了。哇哈哈哈

Delphi 2009 and C++Builder 2009 will be available on Aug. 25 with North American pricing beginning at $399 per license for Professional editions, $1,299 for Enterprise editions and $2,299 for Architect editions.

Embarcadero Technologies从borland公司收购其子公司CodeGear以后将发布新一版本的delphi和C++Builder, Delphi 2009 and C++Builder 2009 for Windows正式版将于8月25号发布.
Embarcadero称这一是多年来改进最大的一个版本。

个人版3000元左右,好象在开发工具里面确实不是很贵。但。。。还会有多少人使用是个问题。而且据说delphi每次更新都需要重新购买授权?而且是有一定的装机次数的。如果是这样,那就贵很多了

bad5d87911c9b89b10c33544f87ffa91

CSS背景

CSS背景

不多说啥了。在网上看到这篇文章,难得是有详细介绍的。。虽然这个功能我很多时候其实已经在用了,但。那都是直接拿来用的,并没有深刻的研究过。今天这里终于看到一个有注释的,就贴上来看看。

这种用法,是被YAHOO所推荐的。因为。这样的用法,降低了图片的下载量。而且并在一起,并不会给图片的大小增加很多。

原文:http://iruif.cn/swd/?p=25
这里只贴重要的内容。请原作者不要伤心。谢谢


图片文件为:

首先我们得控制好要应用小图标的对象的高度. 否则到时候这个图标就会显示异常了.

比如说我们要给 li 标签使用这个小东东, 那么我们就得写上这样的代码:

li {
height: 12px; /* 这个高度等于每个小图标的高度 */
line-height: 12px; /* 这个同上. 但只是有些时候需要写这个而已. */
background: url('icons.gif') 0 -12px; /* 这里的 -12px 就是定义你要使用第几个图标. 如果每个图标的高度都是 12px 的话, 那么我要使用第 N 个图标的话就得写 n*12 . */
padding-top: 0; /* 这个要严格限定为 0 . 否则呢, 哼哼哈莉.. */
padding-bottom: 0; /* 这个也一样.. */
padding-left: 14px; /* 这个肯定是要设定一个值的.. 否则小图标就会被文字覆盖掉.. padding-right 可以设定也可以不设定.. */
margin: 2px 0; /* 如果要设定每个 li 标签之间的距离话, 就要改这个了.. */
overflow: hidden; /* 在有些情况下需要写这个. 具体作用我就不多解释了. */
}
显然, 把小图标都放到一个文件里的话会带来很多的问题. 比如要限定宽度和高度 [也就是内容会显示不完整] , 并且 padding 也将无法使用 [也就是会影响到 border 等属性的效果] .
当然也有解决办法. 那就是 — 把每个小图标的距离拉开, 或者干脆把他们都拆成单独的文件..

如果不明白可以问问原作者。。。

为supesite中的文章添加背景音乐

为supesite中的文章添加背景音乐

以前我写过一篇测试播放器的文章,当然,在我自己的网站是正常了。正好遇到一朋友需要在supesite下面为每篇文章增加不同的背景音乐,于是调试了一下。由于supesite的编辑器会自动过滤一些标签,最终我的处理方案如下:

1、先选中编辑器状态栏中的“源代码”,点击后,输入

<div id='audio_file' style="display:none">aaa.mp3</div>



其中,aaa.mp3就是你要播放的音乐文件,默认在根目录下的music目录里,如果你在里面建立了目录hongkong来存放香港歌英,则aaa.mp3就变成了hongkong/aaa.mp3,即在文件名前要加上目录路径,id=audio_file不能被改变,

2、取消选中源代码,继续编辑你的文章,这时候刚才的 aaa.mp3 会显示在内容里,不用理会他,成功后不会影响文件的编辑的。或者,你也可以在文件内容编辑完毕后,再选中源代码,在源代码的最上面加入这一行就行了。

3、在模版里加上相应的代码

<script language="JavaScript" src="http://www.xxxx.com/public/audioplayer.js"></script>
<script>
try
{
var audio = document.getElementById('audio_file');
if(audio.innerText != ''){
var audio_flash = 'http://www.xxxxx.com/public/player.swf';
var audio_vars = {};
audio_vars.soundFile = 'http://www.xxxxx.com/music/' + audio.innerText;
audio_vars.loop = 'yes';
audio_vars.autostart = 'yes';
set_audioplayer( audio_flash , audio_vars );
}
}
catch (e){}

</script>

4、成功……现在测试

具体的代码就不提供了。网上应该是有的下载。。。。只是提供这个解决方法。

演示地址:http://www.l2foto.com/s/?action-viewnews-itemid-4

测试JS的速度

在mootools的官方网站有一个网页专门用来测试几个框架的速度,大概是:mootools,jquery,prototype,dojo,yui,测试下来jquery的平均速度应该算是最快的。

那个评测下来IE下JS运行速度慢果然是很明显的。同样的测试在IE下面比FF下面,速度慢了一倍左右啊。

不多了。自己测试一下看结果吧。。
http://mootools.net/slickspeed/

e1684acd4db8970cc415a9f918d7adc7

zendframework 1.6终于将SOAP放进去了

zendframework 1.6终于将SOAP放进去了

1.6版本的zf终于将SOAP放进来了,同时也增加了DOJO的支持。不过我没有想通。为什么那么多的JS框架,最终会选择了DOJO。

这些不是我能够想得通的。还是看看到底更新了什么再说吧。

An overview of new features:

  • Dojo Integration
    • JSON-RPC
    • Dojo Data packing
    • Dojo View Helper
    • Dijit integration with Zend_Form & Zend_View
    • Dojo Library Distribution
  • SOAP
    • SOAP Server
    • SOAP Client
    • Autodiscovery
    • WSDL access
    • WSDL Generation
  • Preview of Tooling Project in Laboratory (see /laboratory folder)
    • Command Line Interface
    • Project Asset Management
  • Unit Testing Harness for Controllers
  • Lucene 2.3 Index File Format Support
  • Zend_Session save handler for Database Tables
  • Paginator Component
  • Text/Figlet Support
  • ReCaptcha Service
  • Zend_Config_Xml Attribute Support
  • Character Set Option for DB Adapters
  • Zend File Transfer Component
  • New Media View Helpers (Flash, Quicktime, Object, and Page)
  • Support in Zend_Translate for INI File Format

This obviously marks a very important step towards a high-quality, highly tested 1.6 GA release. Thanks to everyone who has contributed to this release in any way: with patches/check ins, documentation/translations, and bug reports.

But our work is not yet over! Let's do our best to bring this release to the breaking point to find areas we can improve the release for General Availability. Based on your feedback we will determine in the next few weeks whether we require additional release candidates, so please provide feedback on our issue tracker (http://framework.zend.com/issues) as soon as you can and ask any questions/post your experiences on the appropriate mailing list.

Again, the Zend Framework community does NOT recommend this release for production use. We do, however, recommend evaluating new features in this release with existing and new applications.

Enjoy 1.6RC1, and see you on the issue tracker, wiki, and mailing lists!

————END————

不知道:Zend File Transfer Component,这个会给我们带来什么样的惊喜?大文件传输还是其他的?下载源码研究一下,哈哈

Zend_Acl and MVC Integration Part I (Basic Use)

Zend_Acl and MVC Integration Part I (Basic Use)

原文地址:http://devzone.zend.com/article/3509-Zend_Acl-and-MVC-Integration-Part-I-Basic-Use

原文内容:

By Aldemar Bernal

So, what is wrong with Zend_Acl and the current MVC implementation in the Zend Framework? there is nothing wrong, it is just that it gets not too obvious for developers how to achieve an optimal integration between these two important parts of the framework.

First at all, this article is based on the following Zend Framework Proporsal (link), by this moment this proposal is in Pending Recommendation state.

Well, how it works? There are two key components in this proposal:

  1. A Front Controller Plugin: This component resolves if the current user has access to the page which is being opened.
  2. An Action Helper: This component allows you to check whether the current user has access inside a controller.

Based on these two components, let's try them with an example. Let's talk about a website like DevZone, we would need a controller that work with the user management and another one which will deal with article management, as well we need 3 types of users (roles), one for guests, one for writers and another one which will approve the articles; resuming, we have:

Resources:

  1. user controller.
  2. article controller.

Roles:

  1. Guest.
  2. Writer.
  3. Admin.

Setting up the Zend_Acl component

After defined what we want to do, the next step will create a Zend_Acl instance which will reflect our model.

/** Creating the ACL object */
require_once 'Zend/Acl.php';
$myAcl = new Zend_Acl();

Creating the roles

Now we create the roles in our Zend_Acl instance.

/** Creating Roles */
require_once 'Zend/Acl/Role.php';
$myAcl->addRole(new Zend_Acl_Role('guest'))
->addRole(new Zend_Acl_Role('writer'), 'guest')
->addRole(new Zend_Acl_Role('admin'), 'writer');

Creating the resources

And then we create the resources needed (one per controller) and their relationship with the roles we created.

/** Creating resources */
require_once 'Zend/Acl/Resource.php';
$myAcl->add(new Zend_Acl_Resource('user'))
->add(new Zend_Acl_Resource('article'));

Creating the permissions

Now that we added the roles and resources to our Zend_Acl instance, it's time to explain what actions must be available to which roles.

  1. Guest won't have access to edit, add or approve an article.
  2. Writer won't have access to approve an article.
  3. Admin will have complete access.
/** Creating permissions */
$myAcl->allow('guest', 'user')
->deny('guest', 'article')
->allow('guest', 'article', 'view')
->allow('writer', 'article', array('add', 'edit'))
->allow('admin', 'article', 'approve');

Creating the access denied view file

We will need to create a view and an action which will address all those denied users, in order to do it, first we create a new action in our error controller:

class ErrorController extends Zend_Controller_Action
{
....

public function deniedAction()
{
}

....
}

And then we create our view file (/application/views/scripts/error/denied.phtml) with some warning message:

<h1>Error</h1>
<h2>Access denied</h2>
<p>You are trying to access an area which you have not allowed.</p>

Finishing the configuration

Okay, we have setup our Zend_Acl configuration, so far, it doesn't look like something new, but the next step is register the controller plugin, this important part takes the Zend_Acl instance we created and then validates it against the current page being accessed by an user.

/** Setting up the front controller */ 
require_once 'Zend/Controller/Front.php';
$front = Zend_Controller_Front::getInstance();
$front->setControllerDirectory('path/to/controllers');

/** Registering the Plugin object */
require_once 'Zend/Controller/Plugin/Acl.php';
$aclPlugin = new Zend_Controller_Plugin_Acl($myAcl);
$aclPlugin->setRoleName($currentUserRole);

$front->registerPlugin(new Zend_Controller_Plugin_Acl($acl, 'guest'));

/** Dispatching the front controller */
$front->dispatch();

After this configuration is done, once an user enters in our application, depending the role he/she has the page will be displayed or an access denied page will be displayed.

For more information about this you can go to:
Zend_Acl & MVC Integration
and here is a small implementation source code of this:
Source Code

————END————
由于本文并没有什么特别的地方,而且单词也没有什么,故不作翻译。

最常用的链接

最常用的链接

日常工作中,有一些网站是经常要去的,因此在这里加上链接,以后就可以偷懒了,而且,也防止自己以后找不到相应的网站。[逐步更新中]

PHP官方网站   PHP官方手册  PHP下载  PHP snap   pear for PHP

APACHE官方网站  APACHE手册  MYSQL官方网站  MYSQL官方中文手册

SMARTY官方网站  SMARTY手册  smarttemplate官方网站(改名叫quickskin了)

jQuery官方网站  prototype官方网站  mootools官方网站

PYTHON官方网站  PYTHON手册


下面是系统类的链接
FREEBSD操作手册

电视也弹窗

电视也弹窗

偶在网上闲逛。突然发现一段内容,对应家中现有的有线电视情况,突然感到好紧张。。。贴上部分内容,陪我一起震惊吧。

自从用了这个遥控器,我就感觉不对劲儿,怎么赛事正精彩的时侯屏幕上会出来个小窗口提示有奖答题呢? 第一次看到以为是央视搞的,后来频繁的出现感觉有点不对,按遥控器的"退出"键,居然提示,"确定退出么?" 按"确定",居然也要半天才能消失这个小浮动窗口。真是有些震惊啊,这下真的互动了,弹窗广告居然搞到电视上来了!

流氓会武术,谁都挡不住! 相信这个技术会被更多有线电视运营商采用的。到时候面对时不时的弹窗广告,加上原来就有的贴片广告,以及那些"精彩绝伦"的电视购物广告,这电视还能看下去么? 奥运过后,电视关闭!
好佩服现在的厂商呀。这是否和当年的分众一个想法?只是这个想法比分众还疯狂啊。估计是和电信学的吧?