Exemple #1
0
     * @param int $id
     * @return \TestObj
     */
    public static function getCopy($id)
    {
        return parent::getCopy(array('Id' => $id));
    }
    protected static function splitedTbName($n, $isCache)
    {
        return 'VeriCodes';
        //		if($isCache)return 'cache_'.($n%10);
        //		else return 'test_id_v';
    }
}
try {
    $oo = TestObj::getCopy(1);
    $oo->load();
    $oo->registerOn('updateOk', TestObj::onAfterSave);
    //$oo->setField('v', 'val123');
    //$oo->update();
    echo "test.php:";
    echo Sooh\DB\Broker::lastCmd() . "\n";
    $r = $oo->dump();
    var_dump($r);
    echo "<hr>";
    //echo "[done-".$oo->getField('Cellphone')."]";
} catch (\Sooh\DB\Error $e) {
    echo $e->getCode() . ":" . $e->getMessage() . "<br><pre>\n" . $e->strLastCmd . "<br>\n" . $e->getTraceAsString();
} catch (\ErrorException $e) {
    echo $e->getCode() . ":" . $e->getMessage() . "<br><pre>\n" . $e->getTraceAsString();
}
Exemple #2
0
<?php

// 最基本的使用方式
$GLOBALS['CONF']['dbConf'] = array('default' => array('host' => '127.0.0.1', 'user' => 'root', 'pass' => '', 'type' => 'mysql', 'port' => '3306', 'dbEnums' => array('default' => 'db_0', 'TestObj' => 'test')), 'mssql' => array('host' => 'fe_auth.db.dev.ad.jinyinmao.com.cn', 'user' => 'User_nyanya', 'pass' => 'Password01!', 'type' => 'sqlsrv', 'dbEnums' => array('default' => 'master', 'TestObj' => 'FE_Auth.dbo')));
$GLOBALS['CONF']['dbByObj'] = array('TestObj' => 'mssql');
//使用mssql的配置
$db = Sooh\DB\Broker::getInstance('mssql');
//直接执行sql的方式
$rs2 = $db->execCustom(array('sql' => 'select top 1 * from FE_Auth.dbo.VeriCodes where Id=1'));
$r = $db->fetchAssocThenFree($rs2);
//sql server 里datetime2 类型的字段转成timestamp
Sooh\DB\Conv\Datetime::loop_to_timestamp(array('BuildAt'), $r, 'rows');
//使用封装函数获取指定的格式的数据
$pair = $db->getPair('tablename', 'field_as_key', 'field_as_val', array('id]' => 0, 'id<' => 10, 'field_not_null!' => null));