Function that inserts values for an array of fields into a database table public function insert($table, $fields = array(), $values = array()) {
    $fields = '`' . implode ( '`,`', $fields ) . '`';
    $values = "'" . implode ( "','", $values ) . "'";
    $sql = "INSERT INTO {$table} ($fields) VALUES($values)";

    if ($this-&gt;_pdo-&gt;prepare ( $sql )) {
        if ($this-&gt;_pdo-&gt;exec ( $sql )) {
            return true;
        }
    }
    return false;
}


This is my first PHP OOP PDO insert function I have ever written.  My function is working well, but I believe this is not the best way I would have written.  Can somebody guide me on what I might have missed?
There's a couple of issues with it, for start your nested if blocks are unnecessary: instead of manually checking and returning true or false, just return the result of those methods, like so:

return $this-&gt;_pdo-&gt;prepare($sql) and $this-&gt;_pdo-&gt;exec($sql);


Additionally, you have made $fields and $values into optional parameters by making them auto-initialise to empty arrays, however you cannot have an INSERT INTO statement without specifying at least one field and value, therefore instead of making them optional array parameters, you should use type hinting to ensure they are arrays, and then check to make sure that the arguments are correct before you send the query off to the server, something like this:

public function insert($table, array $fields, array $values) {

    $numFields = count($fields);
    $numValues = count($values);

    if($numFields === 0 or $numValues === 0)
        throw new Exception("At least one field and value is required.");
    if($numFields !== $numValues)
        throw new Exception("Mismatched number of field and value arguments.");

    $fields = '`' . implode('`,`', $fields) . '`';
    $values = "'" . implode("','", $values) . "'";
    $sql = "INSERT INTO {$table} ($fields) VALUES($values)";

    return $this-&gt;_pdo-&gt;prepare($sql) and $this-&gt;_pdo-&gt;exec($sql);
}