Proper way to pass query data to methods?
<p>I have a User class and I'm wondering what would be the "most recommended" way to handle insertions?</p>

<p>Option 1: Use an existing object</p>

<pre><code>// insert a new user and return the user id
public function insert() {
    $sql = "INSERT INTO users (username, password, email, avatar, subscribe, created, last_login, valid) VALUES
                              (?, ?, ?, ?, ?, ?, ?, ?)";
    $sth = $this-&gt;db-&gt;prepare($sql);
    $sth-&gt;bindParam(1, $this-&gt;username, PDO::PARAM_STR);
    $sth-&gt;bindParam(2, $this-&gt;password, PDO::PARAM_STR);
    $sth-&gt;bindParam(3, $this-&gt;email, PDO::PARAM_STR);
    $sth-&gt;bindParam(4, $this-&gt;avatar, PDO::PARAM_STR);
    $sth-&gt;bindParam(5, $this-&gt;subscribe, PDO::PARAM_STR);
    $sth-&gt;bindParam(6, $this-&gt;created, PDO::PARAM_STR);
    $sth-&gt;bindParam(7, $this-&gt;last_login, PDO::PARAM_STR);
    $sth-&gt;bindParam(8, $this-&gt;valid, PDO::PARAM_STR);
    $sth-&gt;execute();

    return $this-&gt;db-&gt;lastInsertId();
}
</code></pre>

<p>Option 2: Pass the information in as an array</p>

<pre><code>// insert a new user and return the user id
public function insert(array $fields = array()) {
    if(!empty($fields)) {
        $sql = "INSERT INTO users (username, password, email, avatar, subscribe, created, last_login, valid) VALUES
                                  (:username, :password, :email, :avatar, :subscribe, :created, :last_login, :valid)";
        $sth = $this-&gt;db-&gt;prepare($sql);
        $sth-&gt;execute($fields);

        return $this-&gt;db-&gt;lastInsertId();
    }
}
</code></pre>

<p>Another option? Does it make any difference?</p>
