Submitted by gouki on 2012, April 6, 7:25 PM
不清楚这些博客是否还会连载,要知道连载这东西真的很耗精力,如果编辑器不好、如果不能自动保存,真的很可能是会失去连载的信息的。事实上,我就是因为这些问题放弃了一些文章的连载。辛苦写了上千字,结果因为编辑器的问题一下子消失了。
再过一段时间,我还是会准备将博客转换到typecho或者wordpress上,毕竟这两个博客软件都是可以支持xmlrpc来投稿的。这样,我就可以用第三方软件来投稿了。(firefox有插件,黑黑)
上链接了,不然会被人骂:(如果有更新,我这里也会同步更新链接,或者你就直接移步该作者的博客吧)
- PHP __autoload()方法真的影响性能吗?
- PHP 杂谈《重构-改善既有代码的设计》之一 重新组织你的函数
- PHP 杂谈《重构-改善既有代码的设计》之二 对象之间搬移特性
- PHP 杂谈《重构-改善既有代码的设计》之三 重新组织数据
- PHP 杂谈《重构-改善既有代码的设计》之四 简化条件表达式
暂时只有5篇关于PHP的,这还有一篇对话也可以看看:PHP 跟老大的对话。
因为其中这一段可以拿来共勉:
XML/HTML代码
- 题外话:曾经我在离开一家工作一年的公司的时候!项目经理就跟我说你如果频繁跳槽,会对你的将来的发展是不利的,但是没有告诉我怎么不利?现在我有点明白了,因为我到过的公司很多技术过硬的人,都是在这个公司带过3年以上的人。我发现如果你在一家公司待很长时间,对你的技术提升是很有帮助的。
- 1》 不停的重构代码,提升你的代码质量。
- 我们开始进入公司的时候,一般都是公司急需赶个项目人手缺乏。等项目完成,一般都是1年左右。如果你在公司待足够长的时间,这个项目多多少少会跟你扯上边的,这时候,你会不停的翻看自己的代码,你也会不断的调整代码, 不断的重构你的代码——跟写文章一眼,你不停的看自己写过的文章,你会不停的做修改,越修改你的文章会越让你喜欢。
- 2》业务熟悉,能够更快更好的写出代码!——我个人比较喜欢“行云流水”似的感觉。
- 你如果在一个公司待了很长一段时间,那么你对这个领域是非常熟悉的。新需求上来,你会很快的知道怎么做代码架构,比如上面提到的,你就知道方法中,哪些代码部分可以抽出来,独立做成一个方法;你也会知道,将来什么地方会频繁修改的。——写代码,如行云流水般!
当然不一定就很有道理,但也不是完全没有道理
PHP | 评论:4
| 阅读:20200
Submitted by gouki on 2012, April 5, 9:06 AM
Yii框架的使用者越来越多,虽然大多数情况下都能够被使用的很正常,但偶尔还是有一些小问题,比如mysql对库名和表名区分大小写,但字段名不区分;这个问题就给Yii框架使用者带来很大的烦恼,特别是这个表还不是自己设计的,只是你拿来使用的,这个郁闷程度啊。
于是有人提醒我,应该这么用,在components中的db数组里加入:attributes=>array(PDO::ATTR_CASE,PDO::CASE_LOWER),以达到强制小写的目的,嗯,想法是好的,但是gii没法用了,gii直接报错,排查了半天,发现可能是CMysqlSchema这个类中的createColumn方法导致的错误,因为当你设置为列名小写后,这个方法中的一些判断却还是用的大写,于是很多变量就找不到了,没有办法继续下一步操作,于是我改了一下这个函数:
PHP代码
-
-
-
-
-
- protected function createColumn($column) {
- $column = array_change_key_case($column, CASE_LOWER);
- $c = new CMysqlColumnSchema;
- $c->name = $this->getDbConnection()->getColumnCase() == PDO::CASE_LOWER
- ? strtolower($column['field'])
- : ($this->getDbConnection()->getColumnCase() == PDO::CASE_UPPER ? strtoupper($column['field'])
- : $column['field']);
- $c->rawName = $this->quoteColumnName($c->name);
- $c->allowNull = $column['null'] === 'YES';
- $c->isPrimaryKey = strpos($column['key'], 'PRI') !== false;
- $c->isForeignKey = false;
- $c->init($column['type'], $column['default']);
- $c->autoIncrement = strpos(strtolower($column['extra']), 'auto_increment') !== false;
- return $c;
- }
当然上面的代码很粗燥,我也只是先临时解决这个问题,这么写之后,马上gii就恢复正常了。黑黑
顺便再说一个技巧:以前用gii的时候,对于生成model类都是一个个的输入一个个的生成,总想着应该可以批量生成,但一直不知道如何操作,直到昨天在解决上面的问题时,发现原来在gii里有这样一段代码:
PHP代码
- if($this->tableName[strlen($this->tableName)-1]==='*')
我晶啊,原来那个表名可以写成*啊,这样就是自动生成整个数据库的model了,哎,以前居然一直没在意。
Tags: yii, model
PHP | 评论:0
| 阅读:17604
Submitted by gouki on 2012, March 20, 11:05 PM
http://www.microsoft.com/download/en/confirmation.aspx?id=20098
其实在很久前就有这玩意了,现在居然是3.0了。在win下用这个驱动好啊,支持最新的Sql server,而且速度很快。同时,它居然还支持了PDO。。。
下载下来很方便,有几种不同的文件,根据你当前的情况来设置:
Perform the following steps to download and install the Microsoft Drivers for PHP for SQL Server:
1. Download SQLSRV30.EXE to a temporary directory
2. Run SQLSRV30.EXE
3. When prompted, enter the path to the PHP extensions directory
4. After extracting the files, read the Installation section of the SQLSRV30_Readme.htm file for next steps
看着readme一步一步就Over了。
08年的时候根据第一版的文件写过一个很简单的连接库,替换掉了当时discuz的sql连接库。现在。。。还是用PDO吧
Tags: phpsqlsrv, windows, php
PHP | 评论:0
| 阅读:15091
Submitted by gouki on 2012, March 19, 9:28 PM
Introduction
PDO_SQLSRV is a driver that implements the PHP Data Objects (PDO) interface to enable access from PHP to MS SQL Server (starting with SQL Server 2005) and SQL Azure databases.
Installation
The PDO_SQLSRV extension is enabled by adding appropriate DLL file to your PHP extension directory and the corresponding entry to the php.ini file. The PDO_SQLSRV download comes with several driver files. Which driver file you use will depend on 3 factors: the PHP version you are using, whether you are using thread-safe or non-thread-safe PHP, and whether your PHP installation was compiled with the VC6 or VC9 compiler. For example, if you are running PHP 5.3, you are using non-thread-safe PHP, and your PHP installation was compiled with the VC9 compiler, you should use the php_pdo_sqlsrv_53_nts_vc9.dll file. (You should use a non-thread-safe version compiled with the VC9 compiler if you are using IIS as your web server). If you are running PHP 5.2, you are using thread-safe PHP, and your PHP installation was compiled with the VC6 compiler, you should use the php_pdo_sqlsrv_52_ts_vc6.dll file.
For more information about system requirements, see » SQLSRV System Requirements.
The PDO_SQLSRV extension is only compatible with PHP running on Windows. For Linux, see ODBC and » Microsoft's SQL Server ODBC Driver for Linux.
System Requirements (Microsoft Drivers for PHP for SQL Server)
To access data in a SQL Server 2005 or later database using the Microsoft Drivers for PHP for SQL Server, you must have the following components installed on your computer:
-
Supported operating systems for version 3.0 of the driver include:
-
Supported operating systems for version 2.0 of the driver include:
-
Supported operating systems for version 2.0 of the driver include:
-
Windows Server 2003 Service Pack 1
-
Windows XP Service Pack 3
-
Windows Vista Service Pack 1 or later
-
Windows Server 2008
-
Windows Server 2008 R2
-
Windows 7
-
PHP 5. For information about how to download and install the latest stable binaries, visit http://php.net.
Microsoft Drivers for PHP for SQL Server, version 3.0 requires PHP 5.3.0 or later. If possible, use PHP 5.3.6, or later. The version 2.0 driver works with PHP 5.2.4 or later. If possible, use PHP 5.2.13, or later.
-
A version of the driver file must be in your PHP extension directory. See Driver Versions later in this topic for information about the different driver files. See Loading the Microsoft Drivers for PHP for SQL Server for information on configuring the driver for the PHP runtime.
(See The Data Center for the Microsoft Drivers for PHP for SQL Server for information on where to download the Microsoft Drivers for PHP for SQL Server.)
-
A Web server. Your Web server must be configured to run PHP. For information about hosting PHP applications with Internet Information Services (IIS) 6.0, see Using FastCGI to Host PHP Applications on IIS 6.0. For information about hosting PHP applications with IIS 7.0, see Using FastCGI to Host PHP Applications on IIS 7.0.
The Microsoft Drivers for PHP for SQL Server has been tested using IIS 6 and IIS 7 with FastCGI.
-
The x86 version of SQL Server Native Client is required on the computer where PHP is running. If you are using a 64-bit operating system, the x86 version of SQL Server Native Client will be installed with the x64 version of SQL Server Native Client (do not install the x86 version of SQL Server Native Client on an x64 operating system).
If you are using the SQLSRV driver, sqlsrv_client_info will return information about which version of SQL Server Native Client is being used by the Microsoft Drivers for PHP for SQL Server. If you are using the PDO_SQLSRV driver, you can use PDO::getAttribute to discover the version.
This section lists the drivers that are installed for version 2.0 and version 3.0 of the Microsoft Drivers for PHP for SQL Server. PHP version 5.2 is not supported in version 3.0 of the Microsoft Drivers for PHP for SQL Server.
Follow the installation instructions in Loading the Driver to configure the driver for use with the PHP runtime.
Microsoft Drivers 2.0 for PHP for SQL Server installs several versions of the driver:
Driver file
|
PHP version
|
Thread safe?
|
Use with PHP .dll
|
php_sqlsrv_53_nts_vc6.dll
php_pdo_sqlsrv_53_nts_vc6.dll
|
5.3
|
no
|
php5.dll
|
php_sqlsrv_53_nts_vc9.dll
php_pdo_sqlsrv_53_nts_vc9.dll
|
5.3
|
no
|
php5.dll
|
php_sqlsrv_53_ts_vc6.dll
php_pdo_sqlsrv_53_ts_vc6.dll
|
5.3
|
yes
|
php5ts.dll
|
php_sqlsrv_53_ts_vc9.dll
php_pdo_sqlsrv_53_ts_vc9.dll
|
5.3
|
yes
|
php5ts.dll
|
php_sqlsrv_52_nts_vc6.dll
php_pdo_sqlsrv_52_nts_vc6.dll
|
5.2
|
no
|
php5.dll
|
php_sqlsrv_52_ts_vc6.dll
php_pdo_sqlsrv_52_ts_vc6.dll
|
5.2
|
yes
|
php5ts.dll
|
If the name of the driver file contains "vc9", it should be used with a PHP version compiled with Visual C++ 9.0.
Microsoft Drivers 3.0 for PHP for SQL Server installs several versions of the driver:
Driver file
|
PHP version
|
Thread safe?
|
Use with PHP .dll
|
php_sqlsrv_53_nts.dll
php_pdo_sqlsrv_53_nts.dll
|
5.3
|
no
|
php5.dll
|
php_sqlsrv_53_ts.dll
php_pdo_sqlsrv_53_ts.dll
|
5.3
|
yes
|
php5ts.dll
|
Tags: sqlserver, microsoft, pdo
PHP | 评论:0
| 阅读:20370
Submitted by gouki on 2012, March 15, 3:24 PM
最近在使用phpQuery处理xml的时候发生了一点小问题。由于xml还算是比较规范,但我又不想用simplexml_load_string,所以就偷懒用phpQuery处理了。
但在处理的时候发现一个问题,比如我要处理的内容是:
XML/HTML代码
- <title>揭秘日本巨型OLED地球仪:实时显示地球变化</title>
- <link>http://news.dili360.com/gclw/xxjs/2012/0312/32136.shtml</link>
- <description><a href='http://news.dili360.com/gclw/xxjs/2012/0312/32136.shtml'><img src='http://image.dili360.com/news/gclw/xxjs/2012/0312/36_5132136203_20120312094816.jpg' style='border: 1px solid #000000;'/></a> 新浪科技讯 北京时间3月12日消息,据国外媒体报道,如果你前往日本东京,别忘了去参观一下“未来科学馆”(Miraikan),这里展示着一些最尖端的技术成就。就在去年年中,这里揭幕了全世界首个大型OLED显示屏,直径超过19英尺(约合5.8米)。尽管名叫“Geo-Cosmos”,但这并非一般的地球仪,它几乎能实时显示我们这颗星球上正在发生的一切!全球各地的科学家和研究机构将数据发送给Geo-Cosmos,后者将其呈现给观众。 这..</description>
- <category>中国国家地理网地理资讯频道</category>
- <author>dili360.com</author>
- <pubdate>2012-03-12 09:48:16</pubdate>
请看加红的那一段。
当我用phpQuery处理完后,发现,右边的</link>不见了。其他元素都正常。我的心一下子就碎了。
开始以为页面有问题,但怎么处理都是这样,最终只能将link换成了url来 进行处理。说实话,心是哇凉哇凉的。。
但是,同事在win下面就没有这个问题,我在ubuntu下就有这个问题。(我现在不知道是否我的PHP版本有问题,还是平台的问题,也没有心思深究了)【同事是5.3.9,我是5.3.6】,
Tags: phpquery
PHP | 评论:0
| 阅读:14724