Skip to content

Instantly share code, notes, and snippets.

@fasthold
fasthold / Pdo_Mysql.php
Created July 17, 2011 09:49
简易封装PDO_MySQL
<?php
/**
* Pdo MySql driver wrap
*
* @category Class
* @package Fasthold Own PHP Snippet
* @copyright Copyright (c) 2007
* @license New BSD License
* @author Fasthold Lau ([email protected])
*/
@fasthold
fasthold / 查询包含 sim 的记录
Created March 8, 2011 08:51
简易模糊查询 按相关性排序 SQL语句
SELECT * , IF( `Word` = 'sim', 1, IF( `Word` LIKE 'sim%', 2, IF( `Word` LIKE '%sim', 4, 3 ) ) ) AS `sort` FROM `dblist` WHERE `Word` LIKE '%sim%' ORDER BY `sort` , `Word`
# 得到结果:
1. sim
2. sim*
3. *sim*
4. sim*
@fasthold
fasthold / MapReduce_test.php
Created March 7, 2011 06:39
利用 mongodb mapreduce 计算数量总和
<?php
$mongo = new Mongo();
$db = $mongo->selectDb('firv_exam');
// 要查询的collection
$collection = 'question';
// 构造 map 和 reduce 函数
$map = <<<MAP
function() { emit(this.username,1); } // this.username 相当于 sql 里的 group by username
@fasthold
fasthold / phpunit.xml
Created February 16, 2011 10:01
zend framework phpunit configuration
<phpunit bootstrap="./TestHelper.php" colors="true">
<!-- Version: $Id$ -->
<testsuite name="Zend Framework Unit Test Demo">
<directory>./</directory>
</testsuite>
<filter>
<whitelist>
<directory suffix=".php">../library/</directory>
<directory suffix=".php">../application/</directory>