close() public method

关闭数据库
public close ( )
Example #1
0
 /**
  * 回滚所有全局事务。同时关闭全局事务选项.
  * @param string $dbname
  */
 static function rollback($dbname = null)
 {
     if ($dbname) {
         if (isset(Db::$txDbs[$dbname])) {
             $db = Db::$txDbs[$dbname];
             $db->rollback();
             unset(TxScope::$txDbs[$dbname]);
             unset(Db::$txDbs[$dbname]);
         }
     } else {
         Db::close();
         self::$tx = false;
     }
 }
Example #2
0
 /**
  * Disconnect from database
  */
 public static function disconnect()
 {
     self::$engine->close();
     self::$engine = null;
 }
Example #3
0
File: Db.php Project: ekowabaka/wyf
 public static function reset($db = null, $atAllCost = false)
 {
     Db::close($db);
     Db::get($db, $atAllCost);
 }
} catch (Exception $e) {
    print "<div style='background:#FFBBBB;border:1px solid red'>";
    print "Test '{$test_name}' (FALL&Oacute;) con mensaje: ({$e->getMessage()})";
    print "</div>";
}
if ($test) {
    $end_benckmark = microtime(true) - $start_benchmark;
    print "<div style='background:#CCFF99;border:1px solid green'>";
    print "Test '{$test_name}' (OK) con tiempo: ({$end_benckmark})";
    print "</div>";
}
$test = true;
$test_name = "CERRAR LA CONEXION A LA BASE DE DATOS";
$start_benchmark = microtime(true);
try {
    $value1 = $db->close();
    if (!$value1) {
        throw new DbException("No se puede cerrar la conexion (1)");
    }
} catch (Exception $e) {
    print "<div style='background:#FFBBBB;border:1px solid red'>";
    print "Test '{$test_name}' (FALL&Oacute;) con mensaje: ({$e->getMessage()})";
    print "</div>";
}
if ($test) {
    $end_benckmark = microtime(true) - $start_benchmark;
    print "<div style='background:#CCFF99;border:1px solid green'>";
    print "Test '{$test_name}' (OK) con tiempo: ({$end_benckmark})";
    print "</div>";
}
print "<div style='background:#CCFF99;border:1px solid green'>";
Example #5
0
<?php

define('DEBUG', true);
$root = realpath(dirname(__FILE__));
$urls = array('^/$' => 'Principal', '^/ingresar$' => 'Ingresar', '^/ingresar/amnesia$' => 'IngresarAmnesia', '^/personas$' => 'Personas', '^/personas/(\\d+)$' => 'PersonasVer', '^/personas/(\\d+)/editar$' => 'PersonasEditar', '^/empresas$' => 'Empresas', '^/empresas/agregar$' => 'EmpresasAgregar', '^/empresas/(\\d+)$' => 'EmpresasVer', '^/empresas/(\\d+)/editar$' => 'EmpresasEditar', '^/empresas/(\\d+)/personas$' => 'EmpresasPersonas', '^/empresas/(\\d+)/personas/agregar$' => 'EmpresasPersonasAgregar', '^/configuracion$' => 'Configuracion', '^/configuracion/apariencia$' => 'ConfiguracionApariencia', '^/salir$' => 'Salir');
include_once "{$root}/config.php";
if (DEBUG) {
    error_reporting(E_ALL);
}
include_once "{$root}/lib/Request.php";
include_once "{$root}/lib/Response.php";
include_once "{$root}/lib/Web.php";
include_once "{$root}/lib/WebBase.php";
include_once "{$root}/lib/Cookies.php";
include_once "{$root}/lib/Validation.php";
include_once "{$root}/lib/String.php";
include_once "{$root}/lib/Lang.php";
include_once "{$root}/lib/Db.php";
include_once "{$root}/lib/Config.php";
include_once "{$root}/lib/Session.php";
Db::open($dbConfig);
Cookies::$prefix = 'EME_';
Session::start();
Web::errorRegister(404, 'Error404');
Web::dispatch($urls);
Db::close();
Example #6
0
    $end = (int) $_POST['txtSize'];
    $len = count($characters);
    $list = array();
    for ($i = 1; $i < 1 << $len; $i++) {
        $c = '';
        for ($j = 0; $j < $len; $j++) {
            if ($i & 1 << $j) {
                $c .= $a[$j];
            }
        }
        $list[] = $c;
    }
    print_r($list);
    //$query = "INSERT INTO " . $_POST['txtTableName'] . " (PasswordValue) VALUES ('" . $value . "')";
    //$link -> query($query);
    Db::close($link);
}
?>


</form>

<script type="text/javascript">

    $(document).ready(function(){

        $('#txtTableName').focus();

    });

</script>
Example #7
0
$Data->cat_id = "";
if (!is_null($Data->n_cat_id) && trim($Data->n_cat_id) != '') {
    $ShinshaDB = new Db();
    if ($ShinshaDB->connect(SHINSHA) == -1) {
        $Logger->error("DBコネクションエラーです。SHINSHA");
        _error(1);
        exit;
    }
    $result = $ShinshaDB->query("SELECT cat_id FROM catalog_master WHERE cat_id = " . $Data->n_cat_id);
    if ($result != -1) {
        if (pg_num_rows($result) > 0) {
            $Data->cat_id = $Data->n_cat_id;
        }
        pg_free_result($result);
    }
    $ShinshaDB->close();
}
$Zaiko->setZaikoData($Data);
// アイコンデータの取得(一文字づつに分解して、配列化)
$option_values_ary = array();
$length = strlen($Data->option_values);
for ($i = 0; $i < $length; $i++) {
    $option_values_ary[$i] = substr($Data->option_values, $i, 1);
}
$Zaiko->setOptionValues($option_values_ary);
$a_option_values_web = array();
$length = strlen($Data->option_values_web);
for ($i = 0; $i < $length; $i++) {
    $a_option_values_web[$i] = substr($Data->option_values_web, $i, 1);
}
$Zaiko->setOptionValuesWeb($a_option_values_web);
Example #8
0
		color:green;
	}
	</style>

	
</head>
<body>
	<h2>Ejemplo de uso de la clase Db</h2>
<?php 
$db = new Db();
$columns = array('ID', 'Name', 'CountryCode', 'Population');
$resul = $db->select($columns, 'world.city')->limit(10)->exe();
?>
 <h3>Resultado con nombres de las columnas de las tablas</h3>
 <?php 
echo create_table($resul);
echo "<br>";
?>


<h3>Resultado con Alias para las columnas</h3>
<?php 
$columns = array('ID', 'Name', 'CountryCode', 'Population');
$resul = $db->select($columns, 'world.city')->where('CountryCode', '=', 'AFG')->andd('Population', '>', '130000')->exe();
$alias = array('Id', 'Nombre', 'Código de país', 'Población');
echo create_table($resul, $alias);
echo "<br>";
$db->close();
?>
</body>
</html>
/**
 * 
 * @param Db $db
 * @param int $foodid
 */
function checkExist(&$db, $foodid)
{
    $sql = "select food_id from canteen_food where food_id={$foodid};";
    $res = $db->query($sql);
    if ($res !== false) {
        if (!empty($res)) {
            echo getJsonResponse(3, "食物已经存在", null);
            $db->rollback();
            //回滚
            $db->close();
            exit;
        }
        $sql2 = "select user_id from recommendedfood where user_id={$_POST['user_id']} and \n\t\t canteen_id={$_POST['canteen_id']} and food_id={$foodid};";
        $res2 = $db->query($sql2);
        if ($res2 !== false) {
            if (!empty($res2)) {
                echo getJsonResponse(4, "食物已经推荐给食堂", null);
                $db->rollback();
                //回滚
                $db->close();
                exit;
            }
        } else {
            echo getJsonResponse(1, $db->error, null);
            Log::error_log('database error:' . $db->error . ' in ' . basename(__FILE__));
            $db->rollback();
            $db->close();
            exit;
        }
    } else {
        echo getJsonResponse(1, $db->error, null);
        Log::error_log('database error:' . $db->error . ' in ' . basename(__FILE__));
        $db->rollback();
        $db->close();
        exit;
    }
}