<?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.
<?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);
$this->password = '******'; $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)