/**
  * Creates a new Factencuesta model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     // CONEXION A LA BASE DE DATOS PARA REALIZAR CONSULTAS VIA SQL EN LA DB
     $db = new \yii\db\Connection(['dsn' => 'pgsql:host=localhost;port=5432;dbname=db_sinsch', 'username' => 'nuestroswawas', 'password' => '4358']);
     $db->open();
     $nom_tec = Yii::$app->user->identity->username;
     $tecnico = $db->createCommand('SELECT 
                                     tecnico.id_tecn
                                   FROM 
                                     public."user", 
                                     public.tecnico
                                   WHERE 
                                     "user".username = tecnico.nombre_corto AND 
                                     tecnico.nombre_corto = :nom_tec', [':nom_tec' => $nom_tec])->queryScalar();
     $model = new Factencuesta();
     $model->num_tom = 2;
     $model->fec_ini_tom = '23-07-2015';
     $model->fec_fin_tom = '23-08-2015';
     $model->id_tecn = $tecnico;
     //  $model -> id_tecn = $nom_tec;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['ninio/create', 'id' => $model->id_enc]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Example #2
0
/**
 * 数据对象方法
 * @param string $orgcode
 * @param string $type  	master(可读可写)|slave(只读实例) 主从模式选择 ,默认是主实例,可读可写
 * @param bool   $auto_open 是否自动完成初始化open操作,兼容操作
 * @throws Exception
 * @return \yii\db\Connection  返回主从对象,根据type来判断
 */
function DB($orgcode = "", $auto_open = true)
{
    $orgcode = empty($orgcode) ? I("__orgcode") : $orgcode;
    static $dbObj = [];
    if (empty($orgcode)) {
        throw new Exception("未找到租户编码", "110000");
    }
    $dbObj_key = $orgcode;
    // 租户主从类型对象标识
    if (isset($dbObj[$dbObj_key])) {
        return $dbObj[$dbObj_key];
    }
    if ($orgcode == "config") {
        $db = \Yii::$app->db;
    } elseif ($orgcode == 'log') {
        $db = \Yii::$app->logDb;
    } elseif ($orgcode == 'task') {
        $db = _get_taskdb();
    } elseif (in_array($orgcode, array_keys(\Yii::$app->params['other_dbs']))) {
        $dbconfig = \Yii::$app->params['other_dbs'][$orgcode];
        $db = \Yii::createObject($dbconfig);
    } else {
        $dbconfig = _get_dbconfig($orgcode);
        $db = new \yii\db\Connection($dbconfig);
    }
    if ($auto_open) {
        $db->open();
    }
    //是否开启自动连接模式,兼容只调用DB方法默认为开启状态
    $dbObj[$dbObj_key] = $db;
    return $db;
}
Example #3
0
 public function checkDbInfo()
 {
     $this->_dbConfig = ['dsn' => 'mysql:host=' . $this->host . ';dbname=' . $this->dbname, 'username' => $this->username, 'password' => $this->password, 'tablePrefix' => $this->tablePrefix, 'charset' => 'utf8'];
     $db = new \yii\db\Connection($this->_dbConfig);
     //		try {
     $db->open();
     //		} catch (\yii\db\Exception $e) {
     //			throw new \yii\base\InvalidParamException('数据库连接出错:'. $e->getMessage());
     //		}
     return $db;
 }
Example #4
0
 public function actionSignup()
 {
     $signup = new signupForm();
     if ($signup->load(Yii::$app->request->post()) && $signup->validate()) {
         echo 'success!';
         echo '<br>' . $signup->username . "<br>";
         // выбираем шаблон БД
         $db = new \yii\db\Connection(['dsn' => 'mysql:host=localhost;dbname=it_service_template', 'username' => 'root', 'password' => '', 'charset' => 'utf8']);
         $have_db = $db->createCommand('SHOW DATABASES LIKE "my_new_db"')->queryOne();
         // проверяем таблицу accounts базы данных it_service_system на наличие аккаунта
         $account = accounts::find()->where(['name' => $signup->username])->andWhere(['email' => $signup->email])->one();
         if (!$have_db && !$account) {
             // добавляем запись в таблицу аккаунта
             $db->createCommand('CREATE DATABASE  my_new_db CHARACTER SET utf8 COLLATE utf8_general_ci')->execute();
             //TODO: копируем таблицы из it_service_template в it_service_account_{account_id}
             // Получаем список таблиц из шаблона
             $template_tables = $db->createCommand('SHOW TABLES')->query();
             // echo 'список таблиц из шаблона: <br>';
             // foreach ( $template_tables as $t_table ){
             // foreach ( $t_table as $ta ) echo $ta . '<br>';
             // }
             // подключаемся к БД аккаунта
             $db = new \yii\db\Connection(['dsn' => 'mysql:host=localhost;dbname=my_new_db', 'username' => 'root', 'password' => '', 'charset' => 'utf8']);
             // создаем таблицы в новой БД по шаблону
             foreach ($template_tables as $t_table) {
                 foreach ($t_table as $ta) {
                     $db->createCommand('CREATE TABLE ' . $ta . ' LIKE it_service_template.' . $ta)->execute();
                 }
             }
             //TODO: скопировать данные справочников из таблиц шаблонной базы
             //$template_db_cartridge_types = CartridgeType::findAll();
             // заносим аккаунт в таблицу it_service_system.accounts
             //-------------------------------------------------------------------------
         } else {
             echo "БД уже есть! : ";
             $ttt = json_encode($have_db);
             print_r($ttt . '<br>');
         }
     } else {
         return $this->render('signup', ['model' => $signup]);
     }
 }
Example #5
0
 /**
  * @param  boolean            $reset whether to clean up the test database
  * @return \yii\db\Connection
  */
 public function getConnection($reset = true)
 {
     if ($this->_connection === null) {
         $databases = $this->getParam('databases');
         $params = $databases['mysql'];
         $db = new \yii\db\Connection();
         $db->dsn = $params['dsn'];
         $db->username = $params['username'];
         $db->password = $params['password'];
         if ($reset) {
             $db->open();
             $lines = explode(';', file_get_contents($params['fixture']));
             foreach ($lines as $line) {
                 if (trim($line) !== '') {
                     $db->pdo->exec($line);
                 }
             }
         }
         $this->_connection = $db;
     }
     return $this->_connection;
 }
Example #6
0
File: Com.php Project: gtyd/jira
 /**
  * 获取task_db连接的单例对象
  * @return \yii\db\Connection
  */
 public function task_db($auto_open = true)
 {
     static $db;
     //单例task_db对象
     if (empty($db)) {
         $conf = \mysoft\pubservice\Conf::getConfig('task_db_config');
         if (empty($conf)) {
             throw new \Exception("task_db config not in configsettings");
         }
         $conf = json_decode($conf, true);
         $dbname = 'task';
         //默认数据库名
         if (isset($conf['dbname']) && $conf['dbname']) {
             //便于调试如果配置里填写过dbname的话这里直接替换
             $dbname = trim($conf['dbname']);
         }
         $conn_arr = ['dsn' => 'mysql:host=' . $conf["host"] . ';port=' . $conf['port'] . ';dbname=' . $dbname, 'username' => $conf["user_name"], 'password' => $conf["password"]];
         $db = new \yii\db\Connection($conn_arr);
         if ($auto_open) {
             $db->open();
         }
     }
     return $db;
 }
/**
 * 数据对象方法
 * @param string $orgcode
 * @param string $type  	master(可读可写)|slave(只读实例) 主从模式选择 ,默认是主实例,可读可写
 * @param bool   $auto_open 是否自动完成初始化open操作,兼容操作
 * @throws Exception
 * @return \yii\db\Connection  返回主从对象,根据type来判断
 */
function DB($orgcode = "", $type = 'master', $auto_open = true)
{
    if ($orgcode == "config") {
        return \Yii::$app->db;
    }
    $orgcode = empty($orgcode) ? I("__orgcode") : $orgcode;
    static $dbObj = [];
    if (empty($orgcode)) {
        throw new Exception("未找到租户编码", "110000");
    }
    $dbObj_key = $orgcode . '_' . $type;
    // 租户主从类型对象标识
    if (isset($dbObj[$dbObj_key])) {
        return $dbObj[$dbObj_key];
    }
    $dbconfig = _get_dbconfig($orgcode, $type);
    $db = new \yii\db\Connection(['dsn' => 'mysql:host=' . $dbconfig["host"] . ';dbname=' . $dbconfig["database"], 'username' => $dbconfig["uid"], 'password' => $dbconfig["pwd"]]);
    if ($auto_open) {
        $db->open();
    }
    //是否开启自动连接模式,兼容只调用DB方法默认为开启状态
    $dbObj[$dbObj_key] = $db;
    return $db;
}
Example #8
0
 $host = $_POST['host'];
 $database = $_POST['database'];
 $username = $_POST['username'];
 $password = $_POST['password'];
 if ($host == '') {
     $errors .= "Host is a required field.<br/>";
 }
 if (empty($database)) {
     $errors .= "Database is a required field.<br/> ";
 }
 if (empty($username)) {
     $errors .= "Username is a required field. ";
 }
 if (empty($errors)) {
     try {
         $db = new yii\db\Connection(['dsn' => 'mysql:host=' . $host . ';dbname=' . $database, 'username' => $username, 'password' => $password, 'charset' => 'utf8']);
         $count = $db->createCommand('SHOW TABLES FROM ' . $database)->execute();
         $file_php = dirname(__FILE__) . '/../../../../../common/config/main-local.php';
         $new_string = "<?php\n                                            \nreturn [\n                                                \n'components' => [\n                                                    \n'db' => [\n                                                        \n'class' => 'yii\\db\\Connection',";
         $new_string .= "'dsn' => 'mysql:host=" . $host . ";dbname=" . $database . "',";
         $new_string .= "'username' => '" . $username . "',";
         $new_string .= "'password' => '" . $password . "',";
         $new_string .= "'charset' => 'utf8'";
         $new_string .= "\n],\n                                                \n'mailer' => [\n                                                    \n'class' => 'yii\\swiftmailer\\Mailer',\n                                                    \n'viewPath' => '@common/mail',\n                                                    \n'useFileTransport' => true,\n                                                \n],\n                                            \n],\n                                        \n];\n                                    \n";
         $fd_php = fopen($file_php, "w");
         fwrite($fd_php, $new_string);
         fclose($fd_php);
         $url = Url::toRoute('step3', true);
     } catch (Exception $e) {
         //echo $e;
         $errors .= "Database Connection failed. Try again. ";
Example #9
0
 public function saveImageNameToDb($url)
 {
     $connection = new \yii\db\Connection(['dsn' => 'mysql:dbname=yii2advanced2;host=127.0.0.1', 'username' => 'root', 'password' => 'root']);
     $connection->createCommand()->insert('product_image', ['image_url' => $url, 'product_id' => $this->getProductId()])->execute();
 }
Example #10
0
 public function pushparticpants()
 {
     $dbs = new \yii\db\Connection(['dsn' => "mysql:host=196.202.202.131;dbname=shinda2", 'username' => 'root', 'password' => 'FAQU', 'charset' => 'utf8']);
     $data = $dbs->createCommand("SELECT * FROM tbl_participant")->queryAll();
     $columns = $dbs->getTableSchema('tbl_participant')->columnNames;
     $db = \Yii::$app->db;
     $trunc = "SET FOREIGN_KEY_CHECKS = 0;TRUNCATE tbl_participant;";
     $db->createCommand($trunc)->execute();
     $db->createCommand()->update('tbl_blood', ['altered' => NULL])->execute();
     $db->createCommand()->update('tbl_bp_24h', ['altered' => NULL])->execute();
     $db->createCommand()->update('tbl_bp_spot', ['altered' => NULL])->execute();
     $db->createCommand()->update('tbl_monitoring_bp_24_data', ['altered' => NULL])->execute();
     $db->createCommand()->update('tbl_questionnaire', ['altered' => NULL])->execute();
     $db->createCommand()->update('tbl_urine', ['altered' => NULL])->execute();
     $sqls = "";
     foreach ($data as $value) {
         $sql = "INSERT INTO tbl_participant (";
         $values = "";
         for ($index = 0; $index < count($columns); $index++) {
             $col = $columns[$index];
             $vals = $value[$columns[$index]];
             if (empty($vals)) {
                 $val = "NULL";
             } else {
                 $val = "\"{$vals}\"";
             }
             $sql .= $col . ", ";
             $values .= $val . ", ";
         }
         $values = substr($values, 0, -2);
         $sql = substr($sql, 0, -2);
         $sql .= ") VALUES(";
         $sql .= $values . ");";
         $sqls .= $sql;
     }
     $db->createCommand($sqls)->execute();
     return true;
 }
 /**
  * @param  boolean            $reset whether to clean up the test database
  * @param  boolean            $open  whether to open and populate test database
  * @return \yii\db\Connection
  */
 public function getDbConnection($reset = true, $open = true)
 {
     if (!$reset && $this->db) {
         return $this->db;
     }
     $db = new \yii\db\Connection();
     $db->dsn = $this->dbConfig['dsn'];
     if (isset($this->dbConfig['username'])) {
         $db->username = $this->dbConfig['username'];
         $db->password = $this->dbConfig['password'];
     }
     if (isset($this->dbConfig['attributes'])) {
         $db->attributes = $this->dbConfig['attributes'];
     }
     if ($open) {
         $db->open();
         if (!empty($this->dbConfig['fixture'])) {
             $lines = explode(';', file_get_contents($this->dbConfig['fixture']));
             foreach ($lines as $line) {
                 if (trim($line) !== '') {
                     $db->pdo->exec($line);
                 }
             }
         }
     }
     $this->db = $db;
     return $db;
 }
Example #12
0
 public function actionCheckdb()
 {
     $request = Yii::$app->request;
     $db = new \yii\db\Connection(['dsn' => 'mysql:host=' . $request->post('db_host', '') . ';dbname=' . $request->post('db_name', ''), 'username' => $request->post('db_user', ''), 'password' => $request->post('db_password', ''), 'emulatePrepare' => true, 'charset' => 'utf8']);
     try {
         $db->open();
         return '<div class="alert alert-success">Соединение успешно</div>';
     } catch (\Exception $e) {
         return '<div class="alert alert-danger">Ошибка подключения: ' . $e->getMessage() . '</div>';
     }
 }
Example #13
0
 public function actionGrafico()
 {
     $model = new GraficoForm();
     // CONEXION A LA BASE DE DATOS PARA REALIZAR CONSULTAS VIA SQL EN LA DB
     $db = new \yii\db\Connection(['dsn' => 'pgsql:host=localhost;port=5432;dbname=db_sinsch', 'username' => 'nuestroswawas', 'password' => '4358']);
     $db->open();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         // CONSULTA EL TOTAL DE ENCUESTAS HECHAS EN UNA TOMA Y EN UN CANTON
         $total = $db->createCommand('SELECT COUNT (*)
                                             FROM 
                                               public.factencuesta 
                                             WHERE 
                                               factencuesta.num_tom = :num_tom AND 
                                               factencuesta.id_tecn = :canton ', [':num_tom' => $model->num_tom, ':canton' => $model->canton])->queryScalar();
         //---******* CONSULTA ENCUENSTAS HECHAS EN UNA TOMA, CANTON e indicador no_tuvo_adelgazamiento Y DONDE SU VALOR SEA FALSO PARA CALCULOS
         $aux = $db->createCommand('SELECT COUNT (*)
                                             FROM 
                                               public.factencuesta, 
                                               public.nutricion
                                             WHERE 
                                               factencuesta.num_tom = :num_tom AND 
                                               factencuesta.id_tecn = :canton AND
                                               factencuesta.id_nut = nutricion.id_nut AND
                                               nutricion._____no_tuvo_adelgazamiento__p_ = false;', [':num_tom' => $model->num_tom, ':canton' => $model->canton])->queryScalar();
         // calculo del porcentaje del indicador No; tuvo adelgazamiento (P/T)
         $por = $aux * 100 / $total;
         $model->adelgazmiento = $por;
         //---******* CONSULTA ENCUENSTAS HECHAS EN UNA TOMA, CANTON e indicador No:tuvo sobrepeso (P/T) Y DONDE SU VALOR SEA FALSO PARA CALCULOS
         $aux1 = $db->createCommand('SELECT COUNT (*)
                                             FROM 
                                               public.factencuesta, 
                                               public.nutricion
                                             WHERE 
                                               factencuesta.num_tom = :num_tom AND 
                                               factencuesta.id_tecn = :canton AND
                                               factencuesta.id_nut = nutricion.id_nut AND
                                               nutricion._____no_tuvo_sobrepeso__p_t___  = false;', [':num_tom' => $model->num_tom, ':canton' => $model->canton])->queryScalar();
         // calculo del porcentaje del indicador No:tuvo sobrepeso (P/T)
         $por1 = $aux1 * 100 / $total;
         $model->sobrepeso = $por1;
         //---******* CONSULTA ENCUENSTAS HECHAS EN UNA TOMA, CANTON e indicador  Índice No:baja ganancia de peso Y DONDE SU VALOR SEA FALSO PARA CALCULOS
         $aux2 = $db->createCommand('SELECT COUNT (*)
                                             FROM 
                                               public.factencuesta, 
                                               public.nutricion
                                             WHERE 
                                               factencuesta.num_tom = :num_tom AND 
                                               factencuesta.id_tecn = :canton AND
                                               factencuesta.id_nut = nutricion.id_nut AND
                                               nutricion. _____no_baja_ganancia_de_peso__ = false;', [':num_tom' => $model->num_tom, ':canton' => $model->canton])->queryScalar();
         // calculo del porcentaje del indicador Índice Talla-Edad z OMS 2006 OK
         $por2 = $aux2 * 100 / $total;
         $model->ganancia_peso = $por2;
         //---******* CONSULTA ENCUENSTAS HECHAS EN UNA TOMA, CANTON e indicador  No:baja ganancia de talla Y DONDE SU VALOR SEA FALSO PARA CALCULOS
         $aux3 = $db->createCommand('SELECT COUNT (*)
                                             FROM 
                                               public.factencuesta, 
                                               public.nutricion
                                             WHERE 
                                               factencuesta.num_tom = :num_tom AND 
                                               factencuesta.id_tecn = :canton AND
                                               factencuesta.id_nut = nutricion.id_nut AND
                                               nutricion. _____no_baja_ganancia_de_talla_ = false;', [':num_tom' => $model->num_tom, ':canton' => $model->canton])->queryScalar();
         // calculo del porcentaje del indicador Índice Talla-Edad z OMS 2006 OK
         $por3 = $aux3 * 100 / $total;
         $model->ganancia_talla = $por3;
         // calculo porcentaje total indicador 1
         $nutricion = ($por + $por1 + $por2 + $por3) / 4;
         $model->nutricion = $nutricion;
         // Calculo de subindicadores indicador 2
         //---******* CONSULTA ENCUENSTAS HECHAS EN UNA TOMA, CANTON e indicador Recibió lactancia materna Y DONDE SU VALOR SEA FALSO PARA CALCULOS
         $auxali = $db->createCommand('SELECT COUNT (*)
                                             FROM 
                                               public.factencuesta, 
                                               public.alimentacion
                                             WHERE 
                                               factencuesta.num_tom = :num_tom AND 
                                               factencuesta.id_tecn = :canton AND
                                               factencuesta.id_ali = alimentacion.id_ali AND
                                               alimentacion._____recibio_lactancia_materna_= true;', [':num_tom' => $model->num_tom, ':canton' => $model->canton])->queryScalar();
         $porali = $auxali * 100 / $total;
         $model->lactancia = $porali;
         //---******* CONSULTA ENCUENSTAS HECHAS EN UNA TOMA, CANTON e indicador  _____recibio_supl__hierro__chis Y DONDE SU VALOR SEA FALSO PARA CALCULOS
         $auxali1 = $db->createCommand('SELECT COUNT (*)
                                             FROM 
                                               public.factencuesta, 
                                               public.alimentacion
                                             WHERE 
                                               factencuesta.num_tom = :num_tom AND 
                                               factencuesta.id_tecn = :canton AND
                                               factencuesta.id_ali = alimentacion.id_ali AND
                                               alimentacion._____recibio_supl__hierro__chis= true;', [':num_tom' => $model->num_tom, ':canton' => $model->canton])->queryScalar();
         $porali1 = $auxali1 * 100 / $total;
         $model->suplementos = $porali1;
         //---******* CONSULTA ENCUENSTAS HECHAS EN UNA TOMA, CANTON e indicador  _____si_es_gestante__recibio_sua Y DONDE SU VALOR SEA FALSO PARA CALCULOS
         $auxali2 = $db->createCommand('SELECT COUNT (*)
                                             FROM 
                                               public.factencuesta, 
                                               public.alimentacion
                                             WHERE 
                                               factencuesta.num_tom = :num_tom AND 
                                               factencuesta.id_tecn = :canton AND
                                               factencuesta.id_ali = alimentacion.id_ali AND
                                               alimentacion._____si_es_gestante__recibio_su= true;', [':num_tom' => $model->num_tom, ':canton' => $model->canton])->queryScalar();
         $porali2 = $auxali2 * 100 / $total;
         $model->acido_f = $porali2;
         //---******* CONSULTA ENCUENSTAS HECHAS EN UNA TOMA, CANTON e indicador  _____estuvo_al_dia_con_suplemen Y DONDE SU VALOR SEA FALSO PARA CALCULOS
         $auxali3 = $db->createCommand('SELECT COUNT (*)
                                             FROM 
                                               public.factencuesta, 
                                               public.alimentacion
                                             WHERE 
                                               factencuesta.num_tom = :num_tom AND 
                                               factencuesta.id_tecn = :canton AND
                                               factencuesta.id_nut = alimentacion.id_ali AND
                                               alimentacion._____estuvo_al_dia_con_suplemen= true;', [':num_tom' => $model->num_tom, ':canton' => $model->canton])->queryScalar();
         $porali3 = $auxali3 * 100 / $total;
         $model->vitamina_a = $porali3;
         //---******* CONSULTA ENCUENSTAS HECHAS EN UNA TOMA, CANTON e indicador _____no_recibio_algun_alimento_ Y DONDE SU VALOR SEA FALSO PARA CALCULOS
         $auxali4 = $db->createCommand('SELECT COUNT (*)
                                             FROM 
                                               public.factencuesta, 
                                               public.alimentacion
                                             WHERE 
                                               factencuesta.num_tom = :num_tom AND 
                                               factencuesta.id_tecn = :canton AND
                                               factencuesta.id_ali = alimentacion.id_ali AND
                                               alimentacion._____no_recibio_algun_alimento_= true;', [':num_tom' => $model->num_tom, ':canton' => $model->canton])->queryScalar();
         $porali4 = $auxali4 * 100 / $total;
         $model->alimento_distinto = $porali4;
         // calculo porcentaje total indicador 2
         $alimentacion = ($porali + $porali1 + $porali2 + $porali3 + $porali4) / 5;
         $model->alimentado = $alimentacion;
         // Calculo de subindicadores indicador 3
         //---******* CONSULTA ENCUENSTAS HECHAS EN UNA TOMA, CANTON e indicador No tuvo fiebre Y DONDE SU VALOR SEA FALSO PARA CALCULOS
         $auxsal = $db->createCommand('SELECT COUNT (*)
                                             FROM 
                                               public.factencuesta, 
                                               public.salud
                                             WHERE 
                                               factencuesta.num_tom = :num_tom AND 
                                               factencuesta.id_tecn = :canton AND
                                               factencuesta.id_sal = salud.id_sal AND
                                               salud. _____no_tuvo_fiebre__= false;', [':num_tom' => $model->num_tom, ':canton' => $model->canton])->queryScalar();
         $porsal = $auxsal * 100 / $total;
         $model->fiebre = $porsal;
         //---******* CONSULTA ENCUENSTAS HECHAS EN UNA TOMA, CANTON e indicador _____no_si_es_gestante__molesti Y DONDE SU VALOR SEA FALSO PARA CALCULOS
         $auxsal1 = $db->createCommand('SELECT COUNT (*)
                                             FROM 
                                               public.factencuesta, 
                                               public.salud
                                             WHERE 
                                               factencuesta.num_tom = :num_tom AND 
                                               factencuesta.id_tecn = :canton AND
                                               factencuesta.id_sal = salud.id_sal AND
                                               salud._____no_si_es_gestante__molesti= false;', [':num_tom' => $model->num_tom, ':canton' => $model->canton])->queryScalar();
         $porsal1 = $auxsal1 * 100 / $total;
         $model->urinarias = $porsal1;
         //---******* CONSULTA ENCUENSTAS HECHAS EN UNA TOMA, CANTON e indicador _____no_si_es_gestante__dolor_d  Y DONDE SU VALOR SEA FALSO PARA CALCULOS
         $auxsal2 = $db->createCommand('SELECT COUNT (*)
                                             FROM 
                                               public.factencuesta, 
                                               public.salud
                                             WHERE 
                                               factencuesta.num_tom = :num_tom AND 
                                               factencuesta.id_tecn = :canton AND
                                               factencuesta.id_sal = salud.id_sal AND
                                               salud._____no_si_es_gestante__dolor_d= false;', [':num_tom' => $model->num_tom, ':canton' => $model->canton])->queryScalar();
         $porsal2 = $auxsal2 * 100 / $total;
         $model->mareo = $porsal2;
         //---******* CONSULTA ENCUENSTAS HECHAS EN UNA TOMA, CANTON e indicador _____no_si_es_gestante__sangrad  Y DONDE SU VALOR SEA FALSO PARA CALCULOS
         $auxsal3 = $db->createCommand('SELECT COUNT (*)
                                             FROM 
                                               public.factencuesta, 
                                               public.salud
                                             WHERE 
                                               factencuesta.num_tom = :num_tom AND 
                                               factencuesta.id_tecn = :canton AND
                                               factencuesta.id_sal = salud.id_sal AND
                                               salud._____no_si_es_gestante__sangrad= false;', [':num_tom' => $model->num_tom, ':canton' => $model->canton])->queryScalar();
         $porsal3 = $auxsal3 * 100 / $total;
         $model->sangrado = $porsal3;
         //---******* CONSULTA ENCUENSTAS HECHAS EN UNA TOMA, CANTON e indicador _____no_tuvo_diarrea__  Y DONDE SU VALOR SEA FALSO PARA CALCULOS
         $auxsal4 = $db->createCommand('SELECT COUNT (*)
                                             FROM 
                                               public.factencuesta, 
                                               public.salud
                                             WHERE 
                                               factencuesta.num_tom = :num_tom AND 
                                               factencuesta.id_tecn = :canton AND
                                               factencuesta.id_sal = salud.id_sal AND
                                               salud._____no_tuvo_diarrea__= false;', [':num_tom' => $model->num_tom, ':canton' => $model->canton])->queryScalar();
         $porsal4 = $auxsal4 * 100 / $total;
         $model->diarrea = $porsal4;
         // calculo porcentaje total indicador 3
         $salud = ($porsal + $porsal1 + $porsal2 + $porsal3 + $porsal4) / 5;
         $model->salud = $salud;
         // Calculo de subindicadores indicador 4
         //---******* CONSULTA ENCUENSTAS HECHAS EN UNA TOMA, CANTON e indicador ______ha_tenido_algun_ex__lab__ Y DONDE SU VALOR SEA FALSO PARA CALCULOS
         $auxate = $db->createCommand('SELECT COUNT (*)
                                             FROM 
                                               public.factencuesta, 
                                               public.atencion
                                             WHERE 
                                               factencuesta.num_tom = :num_tom AND 
                                               factencuesta.id_tecn = :canton AND
                                               factencuesta.id_ate = atencion.id_ate AND
                                               atencion.______ha_tenido_algun_ex__lab__= true;', [':num_tom' => $model->num_tom, ':canton' => $model->canton])->queryScalar();
         $porate = $auxate * 100 / $total;
         $model->examen = $porate;
         //---******* CONSULTA ENCUENSTAS HECHAS EN UNA TOMA, CANTON e indicador ______ha_tenido_al_menos_una_ec Y DONDE SU VALOR SEA FALSO PARA CALCULOS
         $auxate1 = $db->createCommand('SELECT COUNT (*)
                                             FROM 
                                               public.factencuesta, 
                                               public.atencion
                                             WHERE 
                                               factencuesta.num_tom = :num_tom AND 
                                               factencuesta.id_tecn = :canton AND
                                               factencuesta.id_ate = atencion.id_ate AND
                                               atencion.______ha_tenido_al_menos_una_ec= true;', [':num_tom' => $model->num_tom, ':canton' => $model->canton])->queryScalar();
         $porate1 = $auxate1 * 100 / $total;
         $model->ecografia = $porate1;
         //---******* CONSULTA ENCUENSTAS HECHAS EN UNA TOMA, CANTON e indicador _____tiene_sus_vacunas_al_dia_p Y DONDE SU VALOR SEA FALSO PARA CALCULOS
         $auxate2 = $db->createCommand('SELECT COUNT (*)
                                             FROM 
                                               public.factencuesta, 
                                               public.atencion
                                             WHERE 
                                               factencuesta.num_tom = :num_tom AND 
                                               factencuesta.id_tecn = :canton AND
                                               factencuesta.id_ate = atencion.id_ate AND
                                               atencion._____tiene_sus_vacunas_al_dia_p= true;', [':num_tom' => $model->num_tom, ':canton' => $model->canton])->queryScalar();
         $porate2 = $auxate2 * 100 / $total;
         $model->vacunas = $porate2;
         //---******* CONSULTA ENCUENSTAS HECHAS EN UNA TOMA, CANTON e indicador _____ha_tenido_su_ultimo_contro Y DONDE SU VALOR SEA FALSO PARA CALCULOS
         $auxate3 = $db->createCommand('SELECT COUNT (*)
                                             FROM 
                                               public.factencuesta, 
                                               public.atencion
                                             WHERE 
                                               factencuesta.num_tom = :num_tom AND 
                                               factencuesta.id_tecn = :canton AND
                                               factencuesta.id_ate = atencion.id_ate AND
                                               atencion._____ha_tenido_su_ultimo_contro= true;', [':num_tom' => $model->num_tom, ':canton' => $model->canton])->queryScalar();
         $porate3 = $auxate3 * 100 / $total;
         $model->control = $porate3;
         //---******* CONSULTA ENCUENSTAS HECHAS EN UNA TOMA, CANTON e indicador _____recibio_consejeria_nutrici Y DONDE SU VALOR SEA FALSO PARA CALCULOS
         $auxate4 = $db->createCommand('SELECT COUNT (*)
                                             FROM 
                                               public.factencuesta, 
                                               public.atencion
                                             WHERE 
                                               factencuesta.num_tom = :num_tom AND 
                                               factencuesta.id_tecn = :canton AND
                                               factencuesta.id_ate = atencion.id_ate AND
                                               atencion._____recibio_consejeria_nutrici= true;', [':num_tom' => $model->num_tom, ':canton' => $model->canton])->queryScalar();
         $porate4 = $auxate4 * 100 / $total;
         $model->consejeria_nut = $porate4;
         // calculo porcentaje total indicador 4
         $atencion = ($porate + $porate1 + $porate2 + $porate3 + $porate4) / 5;
         $model->atencion = $atencion;
         // Calculo de subindicadores indicador 5
         //---******* CONSULTA ENCUENSTAS HECHAS EN UNA TOMA, CANTON e indicador _____padre_estuvo_con_nino_ayer Y DONDE SU VALOR SEA FALSO PARA CALCULOS
         $auxcui = $db->createCommand('SELECT COUNT (*)
                                             FROM 
                                               public.factencuesta, 
                                               public.cuidadores
                                             WHERE 
                                               factencuesta.num_tom = :num_tom AND 
                                               factencuesta.id_tecn = :canton AND
                                               factencuesta.id_cui = cuidadores.id_cui AND
                                               cuidadores._____padre_estuvo_con_nino_ayer= true;', [':num_tom' => $model->num_tom, ':canton' => $model->canton])->queryScalar();
         $porcui = $auxcui * 100 / $total;
         $model->est_pad = $porcui;
         //---******* CONSULTA ENCUENSTAS HECHAS EN UNA TOMA, CANTON e indicador _____madre_dio_de_comer_al_nino Y DONDE SU VALOR SEA FALSO PARA CALCULOS
         $auxcui1 = $db->createCommand('SELECT COUNT (*)
                                             FROM 
                                               public.factencuesta, 
                                               public.cuidadores
                                             WHERE 
                                               factencuesta.num_tom = :num_tom AND 
                                               factencuesta.id_tecn = :canton AND
                                               factencuesta.id_cui = cuidadores.id_cui AND
                                               cuidadores._____madre_dio_de_comer_al_nino= true;', [':num_tom' => $model->num_tom, ':canton' => $model->canton])->queryScalar();
         $porcui1 = $auxcui1 * 100 / $total;
         $model->com_aye = $porcui1;
         //---******* CONSULTA ENCUENSTAS HECHAS EN UNA TOMA, CANTON e indicador ______fue_su_madre_o_padre__ Y DONDE SU VALOR SEA FALSO PARA CALCULOS
         $auxcui2 = $db->createCommand('SELECT COUNT (*)
                                             FROM 
                                               public.factencuesta, 
                                               public.cuidadores
                                             WHERE 
                                               factencuesta.num_tom = :num_tom AND 
                                               factencuesta.id_tecn = :canton AND
                                               factencuesta.id_cui = cuidadores.id_cui AND
                                               cuidadores.______fue_su_madre_o_padre__= true;', [':num_tom' => $model->num_tom, ':canton' => $model->canton])->queryScalar();
         $porcui2 = $auxcui2 * 100 / $total;
         $model->fue_mad = $porcui2;
         //---******* CONSULTA ENCUENSTAS HECHAS EN UNA TOMA, CANTON e indicador ______fue_mayor_de_edad__18____ Y DONDE SU VALOR SEA FALSO PARA CALCULOS
         $auxcui3 = $db->createCommand('SELECT COUNT (*)
                                             FROM 
                                               public.factencuesta, 
                                               public.cuidadores
                                             WHERE 
                                               factencuesta.num_tom = :num_tom AND 
                                               factencuesta.id_tecn = :canton AND
                                               factencuesta.id_cui = cuidadores.id_cui AND
                                               cuidadores.______fue_mayor_de_edad__18____= true;', [':num_tom' => $model->num_tom, ':canton' => $model->canton])->queryScalar();
         $porcui3 = $auxcui3 * 100 / $total;
         $model->may_eda = $porcui3;
         //---******* CONSULTA ENCUENSTAS HECHAS EN UNA TOMA, CANTON e indicador ______lee_y_escribe_castellano_Y DONDE SU VALOR SEA FALSO PARA CALCULOS
         $auxcui4 = $db->createCommand('SELECT COUNT (*)
                                             FROM 
                                               public.factencuesta, 
                                               public.cuidadores
                                             WHERE 
                                               factencuesta.num_tom = :num_tom AND 
                                               factencuesta.id_tecn = :canton AND
                                               factencuesta.id_cui = cuidadores.id_cui AND
                                               cuidadores.______lee_y_escribe_castellano_= true;', [':num_tom' => $model->num_tom, ':canton' => $model->canton])->queryScalar();
         $porcui4 = $auxcui4 * 100 / $total;
         $model->castellano = $porcui4;
         // calculo porcentaje total indicador 5
         $cuidador = ($porcui + $porcui1 + $porcui2 + $porcui3 + $porcui4) / 5;
         $model->cuidador = $cuidador;
         // Calculo de subindicadores indicador 6
         //---******* CONSULTA ENCUENSTAS HECHAS EN UNA TOMA, CANTON e indicador _____agua_apta_para_consumo_hum Y DONDE SU VALOR SEA FALSO PARA CALCULOS
         $auxviv = $db->createCommand('SELECT COUNT (*)
                                             FROM 
                                               public.factencuesta, 
                                               public.vivienda
                                             WHERE 
                                               factencuesta.num_tom = :num_tom AND 
                                               factencuesta.id_tecn = :canton AND
                                               factencuesta.id_viv = vivienda.id_viv AND
                                               vivienda._____agua_apta_para_consumo_hum= true;', [':num_tom' => $model->num_tom, ':canton' => $model->canton])->queryScalar();
         $porviv = $auxviv * 100 / $total;
         $model->agu_apt = $porviv;
         //---******* CONSULTA ENCUENSTAS HECHAS EN UNA TOMA, CANTON e indicador _____usa_alcant_pzo_sep_letr_ad Y DONDE SU VALOR SEA FALSO PARA CALCULOS
         $auxviv1 = $db->createCommand('SELECT COUNT (*)
                                             FROM 
                                               public.factencuesta, 
                                               public.vivienda
                                             WHERE 
                                               factencuesta.num_tom = :num_tom AND 
                                               factencuesta.id_tecn = :canton AND
                                               factencuesta.id_viv = vivienda.id_viv AND
                                               vivienda._____usa_alcant_pzo_sep_letr_ad= true;', [':num_tom' => $model->num_tom, ':canton' => $model->canton])->queryScalar();
         $porviv1 = $auxviv1 * 100 / $total;
         $model->alcantarillado = $porviv1;
         //---******* CONSULTA ENCUENSTAS HECHAS EN UNA TOMA, CANTON e indicador _____cocina_mejorada__r__o_en_c Y DONDE SU VALOR SEA FALSO PARA CALCULOS
         $auxviv2 = $db->createCommand('SELECT COUNT (*)
                                             FROM 
                                               public.factencuesta, 
                                               public.vivienda
                                             WHERE 
                                               factencuesta.num_tom = :num_tom AND 
                                               factencuesta.id_tecn = :canton AND
                                               factencuesta.id_viv = vivienda.id_viv AND
                                               vivienda._____cocina_mejorada__r__o_en_c= true;', [':num_tom' => $model->num_tom, ':canton' => $model->canton])->queryScalar();
         $porviv2 = $auxviv2 * 100 / $total;
         $model->cocina = $porviv2;
         //---******* CONSULTA ENCUENSTAS HECHAS EN UNA TOMA, CANTON e indicador _____no_animales_de_consumo_sue Y DONDE SU VALOR SEA FALSO PARA CALCULOS
         $auxviv3 = $db->createCommand('SELECT COUNT (*)
                                             FROM 
                                               public.factencuesta, 
                                               public.vivienda
                                             WHERE 
                                               factencuesta.num_tom = :num_tom AND 
                                               factencuesta.id_tecn = :canton AND
                                               factencuesta.id_viv = vivienda.id_viv AND
                                               vivienda._____no_animales_de_consumo_sue= false;', [':num_tom' => $model->num_tom, ':canton' => $model->canton])->queryScalar();
         $porviv3 = $auxviv3 * 100 / $total;
         $model->ani_con = $porviv3;
         //---******* CONSULTA ENCUENSTAS HECHAS EN UNA TOMA, CANTON e indicador _____no_animales_domesticos_sue Y DONDE SU VALOR SEA FALSO PARA CALCULOS
         $auxviv4 = $db->createCommand('SELECT COUNT (*)
                                             FROM 
                                               public.factencuesta, 
                                               public.vivienda
                                             WHERE 
                                               factencuesta.num_tom = :num_tom AND 
                                               factencuesta.id_tecn = :canton AND
                                               factencuesta.id_viv = vivienda.id_viv AND
                                               vivienda._____no_animales_domesticos_sue= false;', [':num_tom' => $model->num_tom, ':canton' => $model->canton])->queryScalar();
         $porviv4 = $auxviv4 * 100 / $total;
         $model->ani_dom = $porviv4;
         // calculo porcentaje total indicador 6
         $vivienda = ($porviv + $porviv1 + $porviv2 + $porviv3 + $porviv4) / 5;
         $model->vivienda = $vivienda;
         // Calculo de subindicadores indicador 7
         //---******* CONSULTA ENCUENSTAS HECHAS EN UNA TOMA, CANTON e indicador sub1_sal_com Y DONDE SU VALOR SEA FALSO PARA CALCULOS
         $auxsalcomu = $db->createCommand('SELECT COUNT (*)
                                             FROM 
                                               public.factencuesta, 
                                               public.saludablecomunidad
                                             WHERE 
                                               factencuesta.num_tom = :num_tom AND 
                                               factencuesta.id_tecn = :canton AND
                                               factencuesta.id_sal_com = saludablecomunidad.id_sal_com AND
                                               saludablecomunidad.sub1_sal_com= true;', [':num_tom' => $model->num_tom, ':canton' => $model->canton])->queryScalar();
         $porsalcomu = $auxsalcomu * 100 / $total;
         $model->seguridad = $porsalcomu;
         //---******* CONSULTA ENCUENSTAS HECHAS EN UNA TOMA, CANTON e indicador _____madre_c_seg_salud_iess_cam Y DONDE SU VALOR SEA FALSO PARA CALCULOS
         $auxsalcomu1 = $db->createCommand('SELECT COUNT (*)
                                             FROM 
                                               public.factencuesta, 
                                               public.saludablecomunidad
                                             WHERE 
                                               factencuesta.num_tom = :num_tom AND 
                                               factencuesta.id_tecn = :canton AND
                                               factencuesta.id_sal_com = saludablecomunidad.id_sal_com AND
                                               saludablecomunidad._____madre_c_seg_salud_iess_cam= true;', [':num_tom' => $model->num_tom, ':canton' => $model->canton])->queryScalar();
         $porsalcomu1 = $auxsalcomu1 * 100 / $total;
         $model->car_mad = $porsalcomu1;
         //---******* CONSULTA ENCUENSTAS HECHAS EN UNA TOMA, CANTON e indicador _____nino_con_numero_de_identif Y DONDE SU VALOR SEA FALSO PARA CALCULOS
         $auxsalcomu2 = $db->createCommand('SELECT COUNT (*)
                                             FROM 
                                               public.factencuesta, 
                                               public.saludablecomunidad
                                             WHERE 
                                               factencuesta.num_tom = :num_tom AND 
                                               factencuesta.id_tecn = :canton AND
                                               factencuesta.id_sal_com = saludablecomunidad.id_sal_com AND
                                               saludablecomunidad._____nino_con_numero_de_identif= true;', [':num_tom' => $model->num_tom, ':canton' => $model->canton])->queryScalar();
         $porsalcomu2 = $auxsalcomu2 * 100 / $total;
         $model->nin_ced = $porsalcomu2;
         //---******* CONSULTA ENCUENSTAS HECHAS EN UNA TOMA, CANTON e indicador ______tiene_c_i___ Y DONDE SU VALOR SEA FALSO PARA CALCULOS
         $auxsalcomu3 = $db->createCommand('SELECT COUNT (*)
                                             FROM 
                                               public.factencuesta, 
                                               public.saludablecomunidad
                                             WHERE 
                                               factencuesta.num_tom = :num_tom AND 
                                               factencuesta.id_tecn = :canton AND
                                               factencuesta.id_sal_com = saludablecomunidad.id_sal_com AND
                                               saludablecomunidad.______tiene_c_i___= true;', [':num_tom' => $model->num_tom, ':canton' => $model->canton])->queryScalar();
         $porsalcomu3 = $auxsalcomu3 * 100 / $total;
         $model->cedula = $porsalcomu3;
         //---******* CONSULTA ENCUENSTAS HECHAS EN UNA TOMA, CANTON e indicador ______tiene_educacion_primaria_ Y DONDE SU VALOR SEA FALSO PARA CALCULOS
         $auxsalcomu4 = $db->createCommand('SELECT COUNT (*)
                                             FROM 
                                               public.factencuesta, 
                                               public.saludablecomunidad
                                             WHERE 
                                               factencuesta.num_tom = :num_tom AND 
                                               factencuesta.id_tecn = :canton AND
                                               factencuesta.id_sal_com = saludablecomunidad.id_sal_com AND
                                               saludablecomunidad.______tiene_educacion_primaria_= true;', [':num_tom' => $model->num_tom, ':canton' => $model->canton])->queryScalar();
         $porsalcomu4 = $auxsalcomu4 * 100 / $total;
         $model->edu_prim = $porsalcomu4;
         // calculo porcentaje total indicador 7
         $com_sal = ($porsalcomu + $porsalcomu1 + $porsalcomu2 + $porsalcomu3 + $porsalcomu4) / 5;
         $model->com_sal = $com_sal;
         return $this->render('grafico', ['model' => $model]);
         // return $this->render('entry-confirm', ['model' => $model]);
     } else {
         // la página es mostrada inicialmente o hay algún error de validación
         return $this->render('grafico', ['model' => $model]);
     }
 }
Example #14
0
 public function actionStataparstatu()
 {
     $connection = new \yii\db\Connection(['dsn' => 'oci:dbname= //localhost/orcl', 'username' => 'immo_bdd', 'password' => 'immo2015']);
     $connection->open();
     $stru = new Structure();
     $cpt = 0;
     $fonc = null;
     $inst = null;
     $repa = null;
     $cede = null;
     $rebu = null;
     $dispar = null;
     $don = null;
     $debut = new Dat();
     $fin = new Dat();
     $dateSysteme = date('d/m/Y');
     //récupérer date systeme
     $tabSys = explode('/', $dateSysteme);
     //convertir en tableau dont le séparateur est /
     $secSys = mktime(0, 0, 0, $tabSys[1], $tabSys[0], $tabSys[2]);
     //convertir la date en seconde
     // le cas d'affectation
     if ($stru->load(Yii::$app->request->post()) && $debut->load(Yii::$app->request->post()) && $fin->load(Yii::$app->request->post())) {
         $datDebut = $debut->dt;
         $datFin = $fin->datefin;
         $tabDebut = explode('/', $datDebut);
         $secDebut = mktime(0, 0, 0, $tabDebut[1], $tabDebut[0], $tabDebut[2]);
         $datFin = $fin->dt;
         $tabFin = explode('/', $datFin);
         $secFin = mktime(0, 0, 0, $tabFin[1], $tabFin[0], $tabFin[2]);
         if ($secDebut <= $secFin && $secDebut <= $secSys && $secDebut <= $secSys) {
             $strDes = $stru->designation;
             $sieg = strcmp($strDes, "siege");
             $cherag = strcmp($strDes, "Succursale Cheraga");
             $annab = strcmp($strDes, "Succursale Annaba");
             $oran = strcmp($strDes, "Succursale Oran");
             $biens = Affecter::find()->all();
             //$biens = Affecter::find()->where(['and',  'dt'<=$datFin , "dt">='31/08/15'])->all();
             //$command = $connection->createCommand ('select * from "affecter" where "codebien"=21845200031 ')->queryOne();
             if ($sieg == 0) {
                 foreach ($biens as $bien) {
                     $bur = $bien->codebureau;
                     $test = $bur[1];
                     $cmp = strcmp($test, "1");
                     if ($cmp == 0) {
                         $cpt++;
                     }
                 }
                 $fonc = $cpt;
             } elseif ($cherag == 0) {
                 foreach ($biens as $bien) {
                     $bur = $bien->codebureau;
                     $test = $bur[1];
                     $cmp = strcmp($test, "2");
                     if ($cmp == 0) {
                         $cpt++;
                     }
                 }
                 $fonc = $cpt;
             } elseif ($annab == 0) {
                 foreach ($biens as $bien) {
                     $bur = $bien->codebureau;
                     $test = $bur[1];
                     $cmp = strcmp($test, "3");
                     if ($cmp == 0) {
                         $cpt++;
                     }
                 }
                 $fonc = $cpt;
             } elseif ($oran == 0) {
                 foreach ($biens as $bien) {
                     $bur = $bien->codebureau;
                     $test = $bur[1];
                     $cmp = strcmp($test, "4");
                     if ($cmp == 0) {
                         $cpt++;
                     }
                 }
                 $fonc = $cpt;
             } else {
                 $cpt++;
                 $fonc = $cpt;
             }
             //le cas de mise en instance
             $inst = (int) Instance::find()->where(['codestructure' => $stru->designation])->count();
             $repa = (int) Reparer::find()->where(['codestructure' => $stru->designation])->count();
             $cede = (int) Reformer::find()->where(['typereforme' => "Cession", 'codestructure' => $stru->designation])->count();
             $rebu = (int) Reformer::find()->where(['typereforme' => "MAR", 'codestructure' => $stru->designation])->count();
             $dispar = (int) Reformer::find()->where(['typereforme' => "Perdu", 'codestructure' => $stru->designation])->count();
             $don = (int) Reformer::find()->where(['typereforme' => "Don", 'codestructure' => $stru->designation])->count();
         } else {
             Yii::$app->getSession()->setFlash('danger', 'La date fin ne doit pas être supérieure à la date début');
             return $this->render('statParStatu', ['stru' => $stru, 'fonc' => $fonc, 'inst' => $inst, 'repa' => $repa, 'cede' => $cede, 'rebu' => $rebu, 'dispar' => $dispar, 'don' => $don]);
         }
     }
     return $this->render('statParStatu', ['stru' => $stru, 'fonc' => $fonc, 'inst' => $inst, 'repa' => $repa, 'cede' => $cede, 'rebu' => $rebu, 'dispar' => $dispar, 'don' => $don, 'debut' => $debut, 'fin' => $fin]);
 }
Example #15
0
 /**
  * 批量插入疾病及疾病相关信息
  * @author gaoqing
  * 2016年1月15日
  * @param  yii\db\Connection $connection 数据库连接对象
  * @param  string $tableName 表名
  * @param  array $insertParams 插入数据的字段集及值(columns, values)
  * @return string 最后插入的ID值
  */
 private function batchInsertDisease($connection, $tableName, $insertParams)
 {
     if (!isset($insertParams) || empty($insertParams)) {
         throw new \Exception($tableName . "下,无更新数据!");
         return;
     }
     $command = $connection->createCommand()->batchInsert($tableName, $insertParams['columns'], $insertParams['values']);
     return $command->execute();
 }
Example #16
0
 /**
  * Checks that a database connection can be established with the provided credentials.
  *
  * @param yii\db\Connection $connection a [[yii\db\Connection]] object.
  * @return int 0 if a database connection can be established or 1 if the database connection could not be established.
  */
 protected function testDatabaseConnection(&$connection)
 {
     try {
         $connection->open();
         return self::EXIT_CODE_NORMAL;
     } catch (Exception $e) {
         return self::EXIT_CODE_ERROR;
     }
 }
Example #17
0
<?php

return ['id' => 'testapp', 'basePath' => dirname(__DIR__), 'vendorPath' => '../../vendor', 'controllerMap' => ['deferred' => ['class' => DevGroup\DeferredTasks\commands\DeferredController::className()]], 'components' => ['mutex' => ['class' => 'yii\\mutex\\MysqlMutex', 'autoRelease' => false], 'db' => ['class' => yii\db\Connection::className(), 'dsn' => 'mysql:host=localhost;dbname=yii2_deferred_tasks', 'username' => 'root', 'password' => ''], 'cache' => ['class' => 'yii\\caching\\FileCache']]];
Example #18
0
 $host = $_POST['host'];
 $database = $_POST['database'];
 $username = $_POST['username'];
 $password = $_POST['password'];
 if ($host == '') {
     $errors .= "Host is a required field.<br/>";
 }
 if (empty($database)) {
     $errors .= "Database is a required field.<br/> ";
 }
 if (empty($username)) {
     $errors .= "Username is a required field. ";
 }
 if (empty($errors)) {
     try {
         $db = new yii\db\Connection(['dsn' => 'mysql:host=' . $host . ';dbname=' . $database, 'username' => $username, 'password' => $password, 'charset' => 'utf8']);
         $count = $db->createCommand('SHOW TABLES FROM cms')->execute();
         $file_php = dirname(__FILE__) . '/../../../common/config/main-local.php';
         $new_string = "<?php\n                                            \nreturn [\n                                                \n'components' => [\n                                                    \n'db' => [\n                                                        \n'class' => 'yii\\db\\Connection',";
         $new_string .= "'dsn' => 'mysql:host=" . $host . ";dbname=" . $database . "',";
         $new_string .= "'username' => '" . $username . "',";
         $new_string .= "'password' => '" . $password . "',";
         $new_string .= "'charset' => 'utf8'";
         $new_string .= "\n],\n                                                \n'mailer' => [\n                                                    \n'class' => 'yii\\swiftmailer\\Mailer',\n                                                    \n'viewPath' => '@common/mail',\n                                                    \n'useFileTransport' => true,\n                                                \n],\n                                            \n],\n                                        \n];\n                                    \n";
         $fd_php = fopen($file_php, "w");
         fwrite($fd_php, $new_string);
         fclose($fd_php);
         $url = Url::toRoute('step3', true);
     } catch (Exception $e) {
         $errors .= "Database Connection failed. Try again. ";
     }
Example #19
0
 public function getDbShopConnect()
 {
     $settings = Settings::getSettings();
     $db = new \yii\db\Connection(['dsn' => 'mysql:host=' . $settings['db_host'] . ';dbname=' . $settings['db_name'], 'username' => $settings['db_user'], 'password' => $settings['db_password'], 'emulatePrepare' => true, 'charset' => 'utf8']);
     try {
         $db->open();
         return $db;
     } catch (\Exception $e) {
         return false;
     }
 }
Example #20
0
<?php

/* @var $this yii\web\View */
// namespace app\models;
//use Yii;
//use yii\base\Model;
//use yii\data\ActiveDataProvider;
use app\models\Fruits;
//use app\models\CountryFruits;
$this->title = 'Second';
$config = (require Yii::getAlias('@app/config/db.php'));
$db = new yii\db\Connection(['dsn' => $config['dsn'], 'username' => $config['username'], 'password' => $config['password'], 'charset' => $config['charset']]);
//--------------------------------- DAO
echo '<h3>DAO</h3>';
/* 
$db->createCommand()->batchInsert('fruits', ['name', 'color', 'weight'], [
    ['pineapple', 'brown', 60],
    ['persimmon', 'orange', 26],
])->execute();
*/
/* //NOT working for some reason
if($db->createCommand()->createTable('vegetables', [
    'id' => 'pk',
    'name' => 'string',
    'color' => 'string',
    'wegiht' => 'integer',
    'somedata2' => 'integer',])
) {
    echo 'Table created<br>';
} else {
    echo 'error: ' . mysql_error() . '<br>';
Example #21
0
<?php

//phpinfo();
//die();
// var_dump(defined('SAE_MYSQL_HOST_M'));
// $link=mysql_connect(SAE_MYSQL_HOST_M.':'.SAE_MYSQL_PORT,SAE_MYSQL_USER,SAE_MYSQL_PASS);
// if(!$link) echo "FAILD!连接错误,用户名密码不对";
// else echo "OK!可以连接";
$sae = defined('SAE_MYSQL_HOST_M');
$db = $sae ? ['class' => 'yii\\db\\Connection', 'dsn' => 'mysql:host=' . SAE_MYSQL_HOST_M . ';port=' . SAE_MYSQL_PORT . ';dbname=' . SAE_MYSQL_DB, 'username' => SAE_MYSQL_USER, 'password' => SAE_MYSQL_PASS, 'charset' => 'utf8'] : ['class' => 'yii\\db\\Connection', 'dsn' => 'mysql:host=mysql;dbname=yii2advanced', 'username' => 'root', 'password' => 'root', 'charset' => 'utf8'];
include './vendor/yiisoft/yii2/Yii.php';
$connection = new \yii\db\Connection(['dsn' => $db['dsn'], 'username' => $db['username'], 'password' => $db['password']]);
$connection->open();
$command = $connection->createCommand('SELECT * FROM user');
$posts = $command->queryAll();
var_dump($posts);
// $directory = __DIR__;
// $filePath = 'vendor';
// echo $directory.'/'.$filePath;
// $mydir = dir($filePath);
// echo "<ul>\n";
// while($file = $mydir->read())
// {
//    if((is_dir("$directory/$file")) AND ($file!=".") AND ($file!=".."))
//    {
//        echo "<li><font color=\"#ff00cc\"><b>$file</b></font></li>\n";
//    } else {
//        $f = @read_exif_data($filePath,null,true);
//        var_dump($f);
//    }
// }