Check username exist in database CI/php

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
User avatar
php-forum Active User
php-forum Active User
Posts: 315
Joined: Sat Mar 23, 2013 8:24 am
Location: Livonia, MI

Wed Aug 07, 2013 12:48 pm

This might help??? This is how I check to see if a username already exits in a database (I'm using PDO):

Code: Select all

    // Method checks to see if username isn't already taken 
    //and returns true if it is already taken:
    public function isUsernameAvailable() {

        // Connect to PDO database:
        $db = Database::getInstance();
        $pdo = $db->getConnection();

        $query = "
            FROM users
                username = :username1

        $query_params = array(
            ':username1' => $this->username

        // These two statements run the query against your database table.
        $stmt = $pdo->prepare($query);
        $result = $stmt->execute($query_params);

        // The fetch() method returns an array representing the "next" row from
        // the selected results, or false if there are no more rows to fetch.	   	   
        return $row = $stmt->fetch();
        // If a row was returned, then we know a matching username was found in
        // the database already and we should return a boolean value back.	   

php-forum Super User
php-forum Super User
Posts: 1803
Joined: Thu Mar 10, 2011 5:07 pm

Fri Aug 09, 2013 9:05 pm

1).What do you mean by "not working"?

2).you should post this to the codeigniter forum

Post Reply