Double entry in the database?

Asked

Viewed 55 times

0

I’ve been through my code and I can’t find the reason he’s adding two records to the database.

Function:

public static function create($table, array $params) {
    $key = array_keys($params);
    $value = array_values($params);

    $key = "`" . implode("`, `", $key) . "`";
    $value = "'" . implode("', '", $value) . "'";

    $sql = "INSERT INTO `" . self::$_prefix . "{$table}` ({$key}) VALUES ({$value})";

    $pdo = self::get()->query($sql);
    $pdo->execute();
}

Function call:

Connect::create('users', array(
    'name' => 'Guilherme',
    'lastname' => 'Alsdfafdves',
    'email' => '[email protected]',
    'username' => 'caraiosssss',
    'password' => '123456',
));
  • 1

    The execute() I don’t know if it works, the query() already does the Insert

  • opa solved :)

  • Great! Create an answer with the details of how you solved it :)

1 answer

1

I solved my mistake, since the function self::get()->query(); already does the job of executing, just removed the $pdo->execute();.

  • 1

    The execute() is for prepared instructions(prepare())

Browser other questions tagged

You are not signed in. Login or sign up in order to post.