Binding multiple values in pdo

If you want to bind based on type (string, int, etc), then no. If you're fine with binding everything as a string:

$stmt = $db->prepare("...");
$stmt->execute(array(
    'foo' => 'bar',
    'something' => 'else',
    'third' => 'thing',
));

You can always bind values within the arguments of execute() as long as you're fine with the values being treated as PDO::PARAM_STR (string).

$result_set = $pdo->prepare("INSERT INTO `users` (`username`, `password`, `first_name`, `last_name`) VALUES (:username, :password, :first_name, :last_name)");
$result_set->execute(array(
    ':username' => '~user',
    ':password' => '~pass',
    ':first_name' => '~John',
    ':last_name' => '~Doe'
));

You can use the array passed just like any array:

$user = "Nile";
$pdo->execute(array(":user" => $user));

Tags:

Php

Pdo

Bind