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
| 阅读:15513
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
| 阅读:20745
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
| 阅读:15110
Submitted by gouki on 2012, March 13, 9:28 AM
说白了,yiiredis中的AR功能的model其实就是一个hash,只是稍作封装了而已
官方有例子:
Using Redis as a backend for Active Record
It is possible to store active record like structures in redis using ARedisRecord.
Note: this is experimental functionality and may be subject to change
$record = ARedisRecord::model()->findByPk(1); // loads a record with a unique id of 1 $record->name = "a test name"; // sets the name attribute on the record $record->somethingElse = "some other value"; $record->save(); // saves the record to redis $record->delete(); // deletes the record from redis
不过,上面的例子不能直接拿来用,因为ARedisRecord是一个abstract类,所以你得写一个类继承于他才行。
顺便,如果用setAttributes的时候,记得加第二个参数(除非你写了rules),否则一定要加第二个参数,不然save不成功哦。
昨天被它折腾了好久才发现
----
笔记而已
Tags: redis, yiiredis, phpredis
PHP | 评论:0
| 阅读:15606
Submitted by gouki on 2012, March 11, 11:07 AM
该死的command+左箭头。。。写了十分钟的东西全没了。
-------重新开始-----
由于目前的一个项目涉及到的数据库需要跨库跨表操作,而且该库会被频繁的插入、更新、删除,所以相对速度会较慢。但查询量又较大,在一台服务器的情况下,怎么办?分端口主从吧,意义不大,因为某些操作会导致CPU瞬间100%。
这时候我想到了key/value的数据库,想用它来做中间处理,比如大量的内容先经过它,再真正入库,毕竟我不需要过分实时,也不涉及到金钱交易。于是乎就在redis和mongo中间犹豫了。
在这期间咨询了三个人:老王(基于博客http://huoding.com/2012/02/29/146,基于Redis消息系统实现);11爷(redis有pub/sub功能);烂桔(mongo不太适用于单机,redis有内存模式)
基于上述原因,于是选择了redis,那么就开始我的Redis之旅吧
1、安装 Redis ,参考:http://library.linode.com/databases/redis/ubuntu-10.10-maverick(如果我没记错,这应该是11爷推荐的地址,他本来推荐的是Centos下的,但我用的是ubuntu,所以就参考这个了)
先来三个常规操作
XML/HTML代码
- apt-get update
- apt-get upgrade
- apt-get install build-essential
完事之后,接着:
XML/HTML代码
- cd /opt/
- mkdir /opt/redis
- wget http://redis.googlecode.com/files/redis-2.4.8.tar.gz
- tar -zxvf /opt/redis-2.4.8.tar.gz
- cd /opt/redis-2.4.8/
- make
make完后做如下操作,将一些配置文件拷贝到/opt/redis目录下:
XML/HTML代码
- cp /opt/redis-2.4.8/redis.conf /opt/redis/redis.conf.default
- cp /opt/redis-2.4.8/src/redis-benchmark /opt/redis/
- cp /opt/redis-2.4.8/src/redis-cli /opt/redis/
- cp /opt/redis-2.4.8/src/redis-server /opt/redis/
- cp /opt/redis-2.4.8/src/redis-check-aof /opt/redis/
- cp /opt/redis-2.4.8/src/redis-check-dump /opt/redis/
- cp /opt/redis/redis.conf.default /opt/redis/redis.conf
接着,更新/opt/redis/redis.conf:
XML/HTML代码
- daemonize yes
- pidfile /var/run/redis.pid
- logfile /var/log/redis.log
-
- port 6379
- bind 127.0.0.1
- timeout 300
-
- loglevel notice
-
- ## Default configuration options
- databases 16
-
- save 900 1
- save 300 10
- save 60 10000
-
- rdbcompression yes
- dbfilename dump.rdb
-
- dir /opt/redis/
- appendonly no
以上是linode里的配置,你可以参考一下做处理。大部分都一样,但timeout/loglevel/dir这三个参数不太一样。可以看着注释改一下。 linode 中有一个:glueoutputbuf yes ,这个在2.4.8下面会出错,所以我就没有启用它。
接着是加入启用脚本,既然linode有配置参考,那么它就有启动脚本,默认redis是没有给你这些启动脚本的,所以偷懒一下吧,下载linode的脚本:
XML/HTML代码
- cd /opt/
- wget -O init-deb.sh http://library.linode.com/assets/630-redis-init-deb.sh
- adduser --system --no-create-home --disabled-login --disabled-password --group redis
- mv /opt/init-deb.sh /etc/init.d/redis
- chmod +x /etc/init.d/redis
- chown -R redis:redis /opt/redis
- touch /var/log/redis.log
- chown redis:redis /var/log/redis.log
- update-rc.d -f redis defaults
在这一步之后,你就可以直接用/etc/init.d/redis 来 start和stop redis服务了。
2、安装phpredis(https://github.com/nicolasff/phpredis)
在安装之前,先看readme:https://github.com/nicolasff/phpredis/blob/master/README.markdown
看完readme之后你会发现,原来一切是这样的简单啊
OK,先wget 回源代码,然后tar解开目录。。
接着3步搞定:
XML/HTML代码
- phpize
- ./configure
- make && make install
速度超快,make install后,会告诉你redis.so生成在哪里,你将这extension=redis.so,加入到你的php.ini中即可。
3、下载YiiRedis项目。(由于我是用Yii的,所以直接用这个插件了,否则,还是参考一下phpredis的一些用法)
同样,在这里有readme:https://github.com/phpnode/YiiRedis/blob/master/README.md
项目地址:https://github.com/phpnode/YiiRedis(请自行下载)
使用方法也很简单,和db一样,在components下加一个组件:
XML/HTML代码
- "components" => array(
- "redis" => array(
- "class" => "packages.redis.ARedisConnection",
- "hostname" => "localhost",
- "port" => 6379
- ),
- //...
- ),
加完它之后就可以写上一段测试代码了:
PHP代码
- Yii::import("ext.yiiredis.*");
- $list = new ARedisList("aNameForYourListGoesHere");
- $list->add("cats");
- $list->add("dogs");
- $list->add("goods");
- foreach($list as $i => $val) {
- print_r($val) ;
- echo "<br />";
- }
- $list->clear();
直接输出在浏览器中。是不是很HIGH?
------
OK,就介绍到这里,请试用吧。
=------
备注:
$redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_NONE); // don't serialize data
$redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP); // use built-in serialize/unserialize
$redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_IGBINARY); // use igBinary serialize/unserialize
$redis->setOption(Redis::OPT_PREFIX, 'myAppName:'); // use custom prefix on all keys
由于redis默认不做序列化,因此如果要存储PHP的数据,如:数组、对象,那就必须用第二个setOption进行设置,以便 让数据自动序列化
Tags: redis, yiiredis, phpredis
PHP | 评论:2
| 阅读:46007