当前位置: 首页>>代码示例>>PHP>>正文


PHP fetch_all函数代码示例

本文整理汇总了PHP中fetch_all函数的典型用法代码示例。如果您正苦于以下问题:PHP fetch_all函数的具体用法?PHP fetch_all怎么用?PHP fetch_all使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了fetch_all函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: content

function content()
{
    if (!user_logged_in()) {
        return must_log_in();
    }
    $user = fetch_one_or_none('users', 'id', user_logged_in());
    if (!array_key_exists('token', $_GET) || !$_GET['token'] || $_GET['token'] != sha1($user->new_email_address)) {
        $errors[] = 'Invalid reset token';
    }
    # This can happen if two accounts try to change address at similar times.
    if (count($errors) == 0 && count(fetch_all('users', 'email_address', $user->new_email_address))) {
        $errors[] = "A user with this email address already exists";
    }
    if (count($errors) == 0) {
        update_all('users', array('email_address' => $user->new_email_address, 'new_email_address' => null), 'id', user_logged_in());
        ?>
    <h2>Address changed</h2>
    <p>Your email address has been changed to
      <tt><?php 
        esc($user->new_email_address);
        ?>
</tt>.</p>
    <?php 
        return;
    }
    page_header('Address verification failed');
    show_error_list($errors);
}
开发者ID:ras52,项目名称:geneopedia,代码行数:28,代码来源:verify-email.php

示例2: do_login

function do_login()
{
    global $errors;
    $errors = array();
    if (!array_key_exists('email', $_POST) || !$_POST['email'] || !array_key_exists('password', $_POST) || !$_POST['password']) {
        $errors[] = "Please provide both an email address and a password";
    }
    if (count($errors)) {
        return;
    }
    $email = $_POST['email'];
    $password = $_POST['password'];
    error_log("Login attempt from <{$email}>");
    $users = fetch_all('users', 'email_address', $email);
    if (count($users) > 1) {
        die('Multiple users with that address!');
    }
    if (count($users) == 0) {
        $errors[] = 'Incorrect email address';
    } elseif (crypt($password, $users[0]->password_crypt) != $users[0]->password_crypt) {
        $errors[] = 'Incorrect password';
    } elseif (!$users[0]->date_verified) {
        $errors[] = 'Your account is not yet activated';
    } elseif (!$users[0]->date_approved) {
        $errors[] = 'Your account is not yet approved';
    }
    if (count($errors)) {
        return;
    }
    $forever = array_key_exists('forever', $_POST) && $_POST['forever'];
    set_login_cookie($uid = $users[0]->id, $forever ? 2147483647 : 0);
    error_log("Login succeeded from <{$email}>");
    redirect_away();
}
开发者ID:ras52,项目名称:geneopedia,代码行数:34,代码来源:login.php

示例3: login_user

function login_user($connection, $post)
{
    $_SESSION['login_errors'] = array();
    if (empty($post['user_name'])) {
        $_SESSION['login_errors'][] = 'User Name cannot be blank';
    }
    if (empty($post['password'])) {
        $_SESSION['login_errors'][] = 'Password cannot be blank';
    }
    if (count($_SESSION['login_errors']) > 0) {
        header('Location: login.php');
    } else {
        $user_name = mysqli_real_escape_string($connection, $post['user_name']);
        $password = mysqli_real_escape_string($connection, $post['password']);
        $query = "SELECT * FROM users WHERE users.user_name = '{$user_name}'";
        $result = fetch_all($query);
        if (!empty($result) && $result[0]['password'] == $password) {
            $_SESSION['user_name'] = $user_name;
            $_SESSION['user_id'] = $result[0]['id'];
            header('Location: success.php');
        } else {
            $_SESSION['login_errors'][] = 'Login Failed';
            header('Location: login.php');
        }
    }
}
开发者ID:jenst44,项目名称:Procedural-PHP-practice,代码行数:26,代码来源:loginProcess.php

示例4: get_column_names_by_table_name

function get_column_names_by_table_name($table)
{
    $result_one_row = fetch_all(mysql_query("SELECT * FROM `{$table}` LIMIT 1"));
    $table_column_names = array();
    for ($i = 0; $i < mysql_num_fields($result_one_row); ++$i) {
        $table_column_names[] = mysql_field_name($result_one_row, $i);
    }
    return $table_column_names;
}
开发者ID:terry80504,项目名称:MySQL-HBase-SQLBridge,代码行数:9,代码来源:common.php

示例5: content

function content()
{
    if (!user_logged_in()) {
        return must_log_in();
    }
    $user = fetch_one_or_none('users', 'id', user_logged_in());
    $errors = array();
    if (array_key_exists('change', $_POST)) {
        if (!isset($_POST['email']) || !$_POST['email']) {
            $errors[] = "Please enter an email address";
        } else {
            $email = $_POST['email'];
            if ($email && !validate_email_address($email)) {
                $errors[] = "Invalid email address";
            }
            if (count($errors) == 0 && count(fetch_all('users', 'email_address', $email))) {
                $errors[] = "A user with this email address already exists";
            }
            if (count($errors) == 0) {
                update_all('users', array('new_email_address' => $email), 'id', user_logged_in());
                send_email_change_email($email, $user->name);
                ?>
        <p>We have sent an email to your new address requesting that you
          confirm that change of address.</p>
        <?php 
                return;
            }
        }
    }
    $fields = array();
    page_header('Change email address');
    show_error_list($errors);
    ?>
 
    <form method="post" action="" accept-charset="UTF-8">
      <div class="fieldrow">
        <div class="field">
          <label>Current address:</label>
          <div><tt><?php 
    esc($user->email_address);
    ?>
</tt></div>
        </div>
      </div>

      <div class="fieldrow">
        <?php 
    text_field($fields, 'email', 'New address');
    ?>
      </div>

      <div class="fieldrow">
        <input type="submit" name="change" value="Change"/>
      </div>
    </form>
  <?php 
}
开发者ID:ras52,项目名称:geneopedia,代码行数:57,代码来源:change-email.php

示例6: get_notes

function get_notes($user_id)
{
    $mysql_link = connect();
    $query = sprintf("SELECT * FROM note WHERE user_id='%s'", mysql_real_escape_string($user_id, $mysql_link));
    $result = mysql_query($query, $mysql_link);
    $notes = fetch_all($result);
    disconnect($mysql_link);
    return $notes;
}
开发者ID:romaimperator,项目名称:trustauth-demo,代码行数:9,代码来源:mysql.php

示例7: get_all_comments

function get_all_comments($message_id)
{
    $query = "SELECT comment,\n\t\t\t\t  users.first_name AS first_name,\n\t\t\t\t  users.last_name AS last_name,\n\t\t\t\t  comments.created_at AS created_at\n\t\t\t\t  FROM comments\n\t\t\t\t  LEFT JOIN messages\n\t\t\t\t  ON comments.message_id = messages.id\n\t\t\t\t  LEFT JOIN users\n\t\t\t\t  ON comments.user_id = users.id\n\t\t\t\t  WHERE message_id = '{$message_id}'";
    $comments = fetch_all($query);
    if (count($comments) > 0) {
        $_SESSION["comments"] = $comments;
    } else {
        $_SESSION["comments"] = array();
    }
}
开发者ID:raymondluu,项目名称:the_wall,代码行数:10,代码来源:wall_process.php

示例8: register_user

function register_user($post)
{
    $_SESSION['errors'] = array();
    // Assigning more secure variables to important fields using escape_this_string function
    $username = escape_this_string($post['username']);
    $email = escape_this_string($post['email']);
    $password = escape_this_string($post['password']);
    // Beginning of validation checks
    // Attempt at validating existing information
    $check_data_query = "SELECT users.username, users.email FROM users";
    $existing_users = fetch_all($check_data_query);
    if (!empty($existing_users)) {
        foreach ($existing_users as $user) {
            if ($username == $user['username']) {
                $_SESSION['errors'][] = 'This username is already taken.';
            }
            if ($email == $user['email']) {
                $_SESSION['errors'][] = 'This email is already in use.';
            }
        }
    }
    // Validating non-existing information to make sure nothing is blank or invalid
    if (empty($username)) {
        $_SESSION['errors'][] = "Username cannot be blank.";
    }
    if (empty($post['first_name'])) {
        $_SESSION['errors'][] = "First name cannot be blank.";
    }
    if (empty($post['last_name'])) {
        $_SESSION['errors'][] = "Last name cannot be blank.";
    }
    if (empty($password)) {
        $_SESSION['errors'][] = "Password fields cannot be blank.";
    }
    if ($post['password'] !== $post['confirm_password']) {
        $_SESSION['errors'][] = "Passwords must match.";
    }
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
        $_SESSION['errors'][] = "Please use a valid email address.";
    }
    if (count($_SESSION['errors']) > 0) {
        header('Location: main.php');
        exit;
    } else {
        // Here I am gonna encrypt both the email and password and then I'm going to make a query to insert that data into the database
        $salt = bin2hex(openssl_random_pseudo_bytes(22));
        $encrypted_password = md5($password . '' . $salt);
        $query = "INSERT INTO users (username, first_name, last_name, email, password, salt, created_at, updated_at) \n\t\t\t  \t\t  VALUES ('{$username}', '{$post['first_name']}', '{$post['last_name']}', '{$email}', '{$encrypted_password}', '{$salt}', NOW(), NOW())";
        run_mysql_query($query);
        $_SESSION['success'] = "User has been successfully created!";
        header('Location: main.php');
        exit;
    }
}
开发者ID:aquang9124,项目名称:the_wall,代码行数:54,代码来源:process.php

示例9: checkduplicate

function checkduplicate($text)
{
    // if the last string is a forward slash, then remove the forward slash and re-evaluate
    if (substr($text, strlen($text) - 1, 1) !== '/') {
        $text = $text . '/';
    }
    $query = 'SELECT * FROM scrapper WHERE ref_link = "' . $text . '"';
    $query_result = fetch_all($query);
    if (count($query_result) == 0) {
        return true;
    }
    return false;
}
开发者ID:eddiebanz,项目名称:tourism,代码行数:13,代码来源:crawler_lib.php

示例10: login_user

function login_user($post)
{
    $query = "SELECT * FROM users WHERE users.email = '{$post['email']}' AND users.password = '{$post['password']}'";
    $user = fetch_all($query);
    if (count($user) > 0) {
        $_SESSION['user_id'] = $user[0]['id'];
        $_SESSION['f_name'] = $user[0]['first_name'];
        $_SESSION['logged_in'] = true;
        header('location: success.php');
    } else {
        $_SESSION['errors'][] = 'check credentials';
        header('location: index.php');
    }
}
开发者ID:Eggsix,项目名称:dojo_projects,代码行数:14,代码来源:process.php

示例11: post_comment

function post_comment($post)
{
    if (empty($post['comments'])) {
        $_SESSION['errors'][] = "Please submit a comment.";
        header("Location: success.php");
        exit;
    } elseif (!empty($post['comments'])) {
        $query = "INSERT INTO comments (comment, created_at, updated_at, users_id, messages_id)\r\n\t\t\t\tVALUES ('{$post['comments']}', NOW(), NOW(), '{$post['user_id']}', '{$post['message_id']}')";
        run_mysql_query($query);
        $query = "SELECT * FROM users\r\n\t\t\t\tLEFT JOIN comments\r\n\t\t\t\tON users.id = comments.users_id";
        $_SESSION['comments'] = fetch_all($query);
        header("Location: success.php");
        die;
    }
}
开发者ID:aespidol,项目名称:wall,代码行数:15,代码来源:wall_process.php

示例12: login_user

function login_user($post)
{
    $query = "SELECT * FROM users\n\t\t\t\t  WHERE users.password = '{$_POST['password']}'\n\t\t\t\t  AND users.email = '{$_POST['email']}'";
    $user = fetch_all($query);
    if (count($user) > 0) {
        $_SESSION["user_id"] = $user[0]["id"];
        $_SESSION["first_name"] = $user[0]["first_name"];
        $_SESSION["logged_in"] = TRUE;
        header("Location: success.php");
        die;
    } else {
        $_SESSION["errors"][] = "Can't find a user with those credentials!";
        header("Location: index.php");
        die;
    }
}
开发者ID:raymondluu,项目名称:login_and_registration,代码行数:16,代码来源:process.php

示例13: login_user

function login_user($post)
{
    $query = "SELECT * FROM users WHERE users.password = '{$post['password']}'\r\n\t\t\tAND users.email = '{$post['email']}'";
    $user = fetch_all($query);
    $query = "SELECT * FROM users\r\n\t\t \t\t  LEFT JOIN messages\r\n\t\t \t\t  ON users.id = messages.users_id\r\n\t\t \t\t  ORDER BY messages.created_at ASC";
    $_SESSION['records'] = fetch_all($query);
    $query = "SELECT * FROM users \r\n\t\t\t\tLEFT JOIN comments\r\n\t\t\t\tON users.id = comments.users_id";
    $_SESSION['comments'] = fetch_all($query);
    if (count($user) > 0) {
        $_SESSION['user_id'] = $user[0]['id'];
        $_SESSION['first_name'] = $user[0]['first_name'];
        $_SESSION['logged_in'] = TRUE;
        header("location: success.php");
    } else {
        $_SESSION['errors'][] = "can't find a user with those credentials";
        header("location: index.php");
        die;
    }
}
开发者ID:aespidol,项目名称:wall,代码行数:19,代码来源:process.php

示例14: login_user

function login_user($post)
{
    $query = "SELECT * FROM users WHERE users.password = '{post['password']}' \n\t\t\t\t  AND users.email = '{$post['email']}'";
    $user = fetch_all($query);
    echo $user;
    if (count($user) > 0) {
        $_SESSION['user_id'] = $user[0]['id'];
        $_SESSION['first_name'] = $user[0]['first_name'];
        $_SESSION['logged_in'] = TRUE;
        header('location: success.php');
    } else {
        //			$_SESSION['errors'][] = array();
        $_SESSION['errors'][] = "can't find a user with those credentials";
        //			header('location: index.php');
        //			die();
    }
    echo $query;
    //		die();
}
开发者ID:jreyles,项目名称:lamp-stack,代码行数:19,代码来源:process.php

示例15: np_character_from_blueprint

 function np_character_from_blueprint($blueprint, $level = 1, $username = 'phaos_npc')
 {
     $this->level = intval($level);
     if ($level < 0) {
         $level = 1;
         echo "<p>bad level input for npc!</p>";
     }
     //define main vars
     $this->id = -1;
     $this->name = $blueprint["name"];
     $this->user = $username;
     $this->cclass = $blueprint["class"];
     $this->race = $blueprint["race"];
     $this->sex = rand(0, 1) ? 'Female' : 'Male';
     $this->image = $blueprint["image_path"];
     $this->age = $this->level * $this->level;
     $this->location = 0;
     //define attribute vars
     $this->strength = (int) ($blueprint["min_damage"] + 3 * ($this->level - 1));
     $this->dexterity = (int) ($blueprint["max_damage"] - $blueprint["min_damage"] + 2 * $this->level + 2);
     $this->wisdom = (int) ($blueprint["xp_given"] / 2 + $this->level);
     //define changeable vars( well except constitution )
     $this->hit_points = $blueprint["hit_points"] + rand(0, $this->level * 3);
     $this->constitution = (int) (($this->hit_points + 10) / 6);
     $this->stamina_points = ($this->constitution + $this->strength) * 5;
     $this->level = $this->level;
     //This are the most significant changes from 0.90
     $ac_left = fairInt($blueprint['AC'] * sqrt($this->level * 0.25));
     $this->xp = fairInt($blueprint["xp_given"] * (0.5 + sqrt($this->level * 0.25)));
     $this->gold = fairInt($blueprint["gold_given"] * (0.5 + sqrt($this->level * 0.25)));
     $this->stat_points = 0;
     //skills
     $this->fight = 4 + $this->level;
     $this->defence = (int) ($blueprint['AC'] / 4 + $this->level - 1);
     $this->lockpick = 1 + (int) ($this->wisdom / 4);
     $this->traps = 1 + (int) ($this->wisdom / 2);
     //define equipment vars
     $this->weapon = 0;
     $this->armor = 0;
     $this->boots = 0;
     $this->shield = 0;
     $this->gloves = 0;
     $this->helm = 0;
     //FIXME: we need natural armor to clothe e.g. dragons
     //FIXME: armor class needs to be spent more evenly among armor types
     if ($ac_left > 0) {
         $armors = fetch_all("select id, armor_class from phaos_armor where armor_class<={$ac_left} order by armor_class DESC LIMIT 1");
         if (count($armors) > 0) {
             $this->armor = $armors[0]['id'];
             $this->armor_ac = $armors[0]['armor_class'];
             $ac_left -= $this->armor_ac;
         }
     }
     if ($ac_left > 0) {
         $boots = fetch_all("select id, armor_class from phaos_boots where armor_class<={$ac_left} order by armor_class DESC LIMIT 1");
         if (count($boots) > 0) {
             $this->boots = $boots[0]['id'];
             $this->boots_ac = $boots[0]['armor_class'];
             $ac_left -= $this->boots_ac;
         }
     }
     //fill weapon:
     $blueprint['avg_damage'] = (int) (($blueprint["min_damage"] + $blueprint["max_damage"]) * 0.5);
     $weapons = fetch_all("select * from phaos_weapons where min_damage<={$blueprint['min_damage']} and {$blueprint['avg_damage']}<= 2*max_damage order by RAND() LIMIT 1");
     if (count($weapons) > 0) {
         $this->weapon = $weapons[0]['id'];
         $this->weapon_min = $weapons[0]['min_damage'];
         $this->weapon_max = $weapons[0]['max_damage'];
         $this->weapon_name = $weapons[0]['name'];
     } else {
         $this->weapon_min = 0;
         $this->weapon_max = 0;
         $this->weapon_name = "natural weapon";
     }
     $this->weaponless = $blueprint['avg_damage'] + 2 * (int) $this->level;
     //calculated stuff
     $this->available_points = $this->strength + $this->dexterity + $this->wisdom + $this->constitution;
     $this->max_hp = $this->constitution * 6;
     $this->max_stamina = ($this->constitution + $this->strength) * 10;
     $this->max_rep = 7;
     if ($this->hit_points > $this->max_hp) {
         $this->max_hp = $this->hit_points;
     }
     if ($this->stamina_points > $this->max_stamina) {
         $this->max_stamina = $this->stamina_points;
     }
     //other stuff
     $actTime = time();
     $this->regen_time = $actTime;
     $this->stamina_time = $actTime;
     $this->rep_time = $actTime;
     $this->no_regen_hp = $blueprint["hit_points"];
     //regeneration
     $this->time_since_regen = $actTime - $this->regen_time;
     $this->stamina_time_since_regen = $actTime - $this->stamina_time;
     $this->rep_time_since_regen = $actTime - $this->rep_time;
     //reputation
     $this->rep_points = rand(0, $this->level - 1);
     $this->rep_helpfull = rand(0, $this->level - 1);
     $this->rep_generious = rand(0, $this->level - 1);
//.........这里部分代码省略.........
开发者ID:renlok,项目名称:PhaosRPG,代码行数:101,代码来源:class_character.php


注:本文中的fetch_all函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。