當前位置: 首頁>>代碼示例>>PHP>>正文


PHP CDatabase::connect方法代碼示例

本文整理匯總了PHP中CDatabase::connect方法的典型用法代碼示例。如果您正苦於以下問題:PHP CDatabase::connect方法的具體用法?PHP CDatabase::connect怎麽用?PHP CDatabase::connect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在CDatabase的用法示例。


在下文中一共展示了CDatabase::connect方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: CDatabase

<?php

include "../../librerias/CDatabase.php";
header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept');
$oDB = new CDatabase();
switch ($_REQUEST['action']) {
    case 'obtener-personas':
        $sSQL = "\n            SELECT  \n                personas.per_id, \n                personas.per_dni, \n                personas.per_nombre, \n                personas.per_apellido\n            \n            FROM \n                personas \n            \n            ORDER BY \n                personas.per_dni\n            ;\n        ";
        //  Creo una conexión.
        $oDB->connect();
        // Ejecutar la consulta SQL.
        $oDB->query($sSQL);
        // Desconectarse de la base de datos.
        $oDB->disconnect();
        // Guardar resultado de la consulta SQL en un arreglo.
        $arr = $oDB->resultToArray();
        // Convierte un string a formato JSON.
        print json_encode($arr);
        break;
    case 'agregar-donacion':
        $donacion = json_decode(file_get_contents("php://input"));
        //echo "$donacion->nombre";
        $valores = "(" . "'" . $donacion->don_fecha . "', " . $donacion->per_id . ")";
        $sSQL = "\n            INSERT INTO donaciones (\n                don_fecha, \n                don_persona) \n            \n            VALUES " . $valores . ";";
        /*
        $stringPrueba = "abc";
        echo ("String: " . $sSQL);
        */
        // Creo una conexión.
        $oDB->connect();
        // Ejecuto la consulta.
開發者ID:robysottini,項目名稱:donaciones,代碼行數:31,代碼來源:formulario-donacion.php

示例2: CDatabase

<?php

//инициализируем класс БД
require PATH_CORE . 'database/database.php';
$oDb = new CDatabase('mysql', 'mysql:host=' . DB_HOST_SYSGEN . ';dbname=' . DB_NAME_SYSGEN, DB_USER_SYSGEN, DB_PASS_SYSGEN);
//$oDb = new CDatabase('pgsql', 'pgsql:port=5432 dbname='.DB_NAME_SYSGEN, DB_USER_SYSGEN, DB_PASS_SYSGEN);
$oDb->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$oDb->connect();
//инициализируем Config
config::load();
$oConfig =& config::$data;
if (BFF_DEBUG || FORDEV) {
    include PATH_CORE . 'vardump.php';
    $oDb->bShowStatistic = true;
    $oDb->bMakeStatistic = true;
}
//инициализируем Smarty
require PATH_CORE . 'external/smarty/smarty.class.php';
$oSm = new Smarty();
$oSm->force_compile = false;
$oSm->compile_check = true;
$oSm->debugging = false;
$oSm->compile_dir = PATH_BASE . 'tpl_c';
$oSm->config_dir = PATH_BASE . 'config';
$oSm->plugins_dir = array('plugins', 'plugins/bff');
Module::adminCustomCenterArea(false);
$oSm->assign('fordev', FORDEV);
$oSm->assign('site_url', SITEURL);
$oSm->assign_by_ref('config', $oConfig);
開發者ID:Sywooch,項目名稱:dobox,代碼行數:29,代碼來源:init.php

示例3: connect

        $this->password = '123';
        $this->dbname = 'test';
    }
    public function connect()
    {
        echo "Connect to db";
        echo "<pre>";
        print_r($this->host);
        print_r($this->user);
        print_r($this->password);
        print_r($this->dbname);
        echo "</pre>";
    }
}
$db = new CDatabase();
$db->connect();
class CHumen
{
    public static $eyes = 2;
    public static $hands = 2;
    private static $religion = "xxx";
    private $name;
    private $age;
    private $db;
    public function __construct($name = '', $age = 0)
    {
        $this->name = $name;
        $this->age = $age;
        $this->db = new CDatabase();
    }
    public function setName($name)
開發者ID:AleksandrAstapov,項目名稱:Source_IT,代碼行數:31,代碼來源:si_lesson_10_1.php


注:本文中的CDatabase::connect方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。