Name

bind_param( )

Synopsis

$statement_param(index, values[, type])

This associates or binds a value in an SQL statement to a placeholder. Placeholders are indicated by ? in SQL statements and are numbered in the order they appear in the statement, starting with 1. The first argument indicates which placeholder to replace with a given value, the second argument. The datatype may be specified as a third argument.

...
my $sql_stmnt = "SELECT title, publisher
                 FROM books WHERE author = ?";
my $sth = $dbh->prepare($sql_stmnt);
$sth->bind_param(1, $author);
$sth->execute( );
while($sth->fetch( )) {
   print "$title ($publisher) \n";
}

In this example, a placeholder (a question mark) is given in the SQL statement and is replaced with the actual value of $author using bind_param( ). This must be done before the execute( ) is issued.

Get MySQL in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.