コード例 #1
0
ファイル: dbUtil.php プロジェクト: sleepyycat/WebFramework
function setProdNameMap($db, $prodName, $tableName)
{
    $prodNameMap = dbUtil(GetProdNameMap);
    if (array_key_exists($prodName, $prodNameMap)) {
        set_db_result(1, "错误:产品名({$prodName})已存在!");
        return;
    }
    if (in_array($tableName, $prodNameMap)) {
        set_db_result(1, "错误:表名({$tableName})已存在!");
        return;
    }
    $collectionNames = $db->getCollectionNames();
    if (in_array($tableName, $collectionNames)) {
        set_db_result(1, "错误:数据库中的表({$tableName})已存在!");
    }
    $obj = preg_match("/^\\w+\$/", $tableName);
    if ($obj == 0) {
        set_db_result(1, "错误:表名只能是字符或字母下划线组成!");
        return;
    }
    if (strlen($tableName) > 20) {
        set_db_result(1, "错误:表名长度不能大于20个字符");
        return;
    }
    $db->createCollection($tableName);
    $collection = $db->prodTableNameMap;
    $collection->insert(array("prodName" => $prodName, "tableName" => $tableName));
    set_db_result(0, "提示:产品名({$prodName})与表名({$tableName})映射成功!");
}
コード例 #2
0
ファイル: dbLib.php プロジェクト: sleepyycat/WebFramework
function dbUtil()
{
    $args_arr = func_get_args();
    $type = $args_arr[0];
    if ($type != GetStatus && $type != SetStatus) {
        reset_db_result();
    }
    try {
        $mongo = new MongoClient('mongodb://nb403:27127/admin:admin');
        $db = $mongo->svnCodeComment;
        if ($type == LoadCodePathInfoTable) {
            return load_codePathInfoTable($db);
        } elseif ($type == LoadProdTableNameMapInfoTable) {
            return load_prodTableNameMapInfoTable($db);
        } elseif ($type == LoadCodeCommentInfoTable) {
            $prodName = $args_arr[1];
            return load_codeCommentInfoTable($db, $prodName);
        } elseif ($type == SaveCodePathInfo) {
            list($svnAddr, $version, $prodName, $creator) = array_slice($args_arr, 1);
            return save_codePathInfo($db, $svnAddr, $version, $prodName, $creator);
        } elseif ($type == SaveProdTableNameMapInfo) {
            list($prodName, $tableName) = array_slice($args_arr, 1);
            return save_prodTableNameMapInfo($db, $prodName, $tableName);
        } elseif ($type == SaveCodeCommentInfo) {
            list($prodName, $version, $status, $filePath, $commentor, $type, $content, $detail_type, $selected_id) = array_slice($args_arr, 1);
            return save_codeCommentInfo($db, $prodName, $version, $status, $filePath, $commentor, $type, $content, $detail_type, $selected_id);
        } elseif ($type == SetStatus) {
            list($status, $msg) = array_slice($args_arr, 1);
            return set_db_result($status, $msg);
        } elseif ($type == GetStatus) {
            return get_db_result();
        } elseif ($type == CreateCollection) {
            $tableName = $args_arr[1];
            return create_table($db, $tableName);
        }
    } catch (MongoConnectionException $e) {
        set_db_result(1, $e->getMessage());
        return false;
    }
}