182k views
0 votes
A valid PHP statement that can INSERT a record into the member table could use the format

$stmt = “INSERT INTO member (last_name, first_name, expiration) VALUES (?,?,?)”;
$sth = $dbh->prepare ($stmt);

$sth->execute (array (“Einstein”, “Albert”, “2014-03-14”) );
---------------------------------------------------------------------------------------------------------------------------
$stmt = “INSERT INTO member (last_name, first_name, expiration) VALUES (?,?,?)”;
$sth = $dbh->prepare ($stmt);

$sth->bindValue (1, “Einstein”);

$sth->bindValue (2, “Albert”);

$sth->bindValue (3, “2014-03-14”);

$sth->execute ();
--------------------------------------------------------------------------------------------------------------------------
$stmt = “INSERT INTO member (last_name, first_name, expiration)
VALUES (:last_name, :first_name, :expiration)”;
$sth = $dbh->prepare ($stmt);

$sth->bindValue (“:last_name”, “Einstein”);

$sth->bindValue (“:first_name”, “Albert”);

$sth->bindValue (“:expiration”, “2014-03-14”);

$sth->execute ();
--------------------------------------------------------------------------------------------------------------------
All of the above are valid.

Please help me out and explain which answer it is (Answers are separated by the lines)

User Dondondon
by
7.1k points

1 Answer

5 votes

Answer:

The correct answer is: All of the above are valid.

All three statements are valid and will insert a record into the member table. The first two statements use positional placeholders, denoted by the question marks, and bind the values to those placeholders using either the execute method with an array or the bindValue method for each value. The third statement uses named placeholders, denoted by the colon followed by a name, and binds the values to those placeholders using the bindValue method.

Step-by-step explanation:

User Fedvasu
by
7.6k points