has() public method

A convenient function that returns TRUE if exists at least an element that satisfy the where condition specified calling the "where" method before this one.
public has ( string $tableName ) : array
$tableName string The name of the database table to work with.
return array Contains the returned rows from the select query.
Ejemplo n.º 1
0
<?php

require_once 'MysqliDb.php';
require_once 'constantes.php';
$bd = new MysqliDb(SERVER_DB_URL, SERVER_DB_USUARIO, SERVER_DB_PASS, SERVER_DB_NOMBRE);
if (!$bd->ping()) {
    $bd->connect();
}
if ($_SERVER['REQUEST_METHOD'] == REQUEST_METODO_POST) {
    $postdata = json_decode(file_get_contents('php://input'));
    $usuario_form = $postdata->usuario;
    $pass_form = md5($postdata->pass);
    $bd->where(COLUMNA_EMAIL, $usuario_form);
    $bd->where(COLUMNA_PASS, $pass_form);
    if ($bd->has(TABLA_USUARIO)) {
        // CORRECTO
        $accion_form = $postdata->form_accion;
        if ($accion_form == ACCION_OBTENER) {
            $query = $bd->get(TABLA_CATEGORIA);
            $arr = array(RESPUESTA_DATA => $query, RESPUESTA_MENSAJE => MENSAJE_OK, RESPUESTA_ERROR => ERROR_NINGUNO);
        } else {
            if ($accion_form == ACCION_OBTERNER_POR_ID) {
                $parametros = $postdata->form_parametros;
                foreach ($parametros as $parametro_key => $parametro_valor) {
                    //        var_dump($parametro_key);
                    //        var_dump($parametro_valor);
                    foreach ($parametro_valor as $key => $val) {
                        //          var_dump($key);
                        //          var_dump($val);
                        switch ($key) {
                            case PARAMETRO_ID:
Ejemplo n.º 2
0
 public function getAllSheet()
 {
     $db = new MysqliDb(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
     $result = $db->get("trails");
     $trails = array();
     foreach ($result as $id => $trail) {
         $trails[$trail['id']] = $trail;
         $attractions = json_decode(stripslashes($trail['attractions']));
         $trails[$trail['id']]['attractions'] = $attractions;
         $loops = json_decode(stripslashes($trail['loops']));
         $trails[$trail['id']]['loops'] = array();
         foreach ($loops as $id => $data) {
             $trails[$trail['id']]['loops'][$id] = (array) $data;
         }
         $db->where("trail_id", $trail['id']);
         if ($db->has("translations")) {
             $db->where("trail_id", $trail['id']);
             $result2 = $db->get("translations");
             $translations = array();
             foreach ($result2 as $id => $translation) {
                 array_push($translations, $translation['lang']);
             }
             $trails[$trail['id']]['translations'] = $translations;
         } else {
             $trails[$trail['id']]['translations'] = "none";
         }
         $trails[$trail['id']]['satImgURL'] = BASE_URL . $trail['satImgURL'];
         $trails[$trail['id']]['largeImgURL'] = BASE_URL . $trail['largeImgURL'];
         $trails[$trail['id']]['thumbURL'] = BASE_URL . $trail['thumbURL'];
         $trails[$trail['id']]['url'] = BASE_URL . "trail/" . $trail['id'] . "/" . $this->slugify($trail['name']) . "/";
     }
     $total = count($trails);
     $response['trails'] = $trails;
     $response['totalMatched'] = $total;
     return $response;
 }
Ejemplo n.º 3
0
    header("Location: " . $baseurl . "user/new/provider/?status=error&code=password&" . $querystring);
    exit;
}
$secret = "6LfdFBUTAAAAAF40Be_HnpwT_Oj6CyDAsgtLohW_";
$recaptcha = new \ReCaptcha\ReCaptcha($secret);
$resp = $recaptcha->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']);
if ($resp->isSuccess()) {
    // verified!
} else {
    $errors = $resp->getErrorCodes();
    header("Location: " . $baseurl . "user/new/provider/?status=error&code=captcha&" . $querystring . "&respcode=" . http_build_query($errors));
    exit;
}
$db = new MysqliDb(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
$db->where("email", $email);
if ($db->has("users")) {
    header("Location: " . $baseurl . "user/new/provider/?status=error&code=exists&" . $querystring);
    exit;
}
$Auth = new Auth();
// $result = $Auth->createUser($email, $password, $fname, $lname, $is_active = 1, $is_admin = 0, $is_provider = 0, $is_super = 0, $is_verified = 0);
$result = $Auth->createUser($email, $password1, $fn, $ln, 1, 0, 1, 0, 0);
if ($result['status']) {
    $attribute = array('pn' => $pn, 'ph' => $ph, 'title' => $prof, 'zip' => $zip);
    if ($Auth->setAttr($result['id'], $attribute)) {
        header("Location: " . $baseurl . "user/new/provider/done.php?e=" . $email);
    } else {
        die("auth error");
    }
} else {
    die("auth error");
Ejemplo n.º 4
0
 public function setAttr($id, $attribute)
 {
     $db = new MysqliDb(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
     $db->where("id", $id);
     if ($db->has("users")) {
         $db->where('id', $id);
         $user = $db->getOne("users");
         if (empty($user['data'])) {
             $data = $attribute;
         } else {
             $userData = json_decode($user['data'], true);
             $data = array_merge($userData, $attribute);
         }
         $newData = array("data" => json_encode($data));
         $db->where('id', $id);
         if ($db->update('users', $newData)) {
             return true;
         } else {
             return 'update failed: ' . $db->getLastError();
         }
     } else {
         return false;
     }
 }