PHP - Sample Interview Question (Senior Level)

Supposed you want to store an image in the database, what is the correct way to transfer large object data? 
In the following example, the column ? imagedata? is of type binary.

  1. $dbh = new PDO('mysql:host=localhost;dbname=dbname', 'username',
    'password');
    $stmt = $dbh->prepare("INSERT INTO images (imagedata) VALUES
    (?)");
    $fp = fopen('/path/filename.png', 'r');
    $stmt->bindParam(1, $fp, PDO::PARAM_LOB);
    $dbh->beginTransaction();
    $stmt->execute();
    $dbh->commit();
  2. $dbh = new PDO('mysql:host=localhost;dbname=dbname', 'username',
    'password');
    $stmt = $dbh->prepare("INSERT INTO images (imagedata) VALUES
    (?)");
    $file = '/path/filename.png';
    $stmt->bindParam(1, $file, PDO::PARAM_LOB);
    $dbh->beginTransaction();
    $stmt->execute();
    $dbh->commit();
  3. $dbh = new PDO('mysql:host=localhost;dbname=dbname', 'username',
    'password');
    $stmt = $dbh->prepare("INSERT INTO images (imagedata) VALUES
    (?)");
    $fp = readfile('/path/filename.png');
    $stmt->bindParam(1, $fp, PDO::PARAM_LOB);
    $dbh->beginTransaction();
    $stmt->execute();
    $dbh->commit();
  4. $dbh = new PDO('mysql:host=localhost;dbname=dbname', 'username',
    'password');
    $stmt = $dbh->prepare("INSERT INTO images (imagedata) VALUES
    (?)");
    $fp = file_get_contents('/var/www/favicon.ico');
    $stmt->bindParam(1, $fp, PDO::PARAM_BINARY);
    $stmt->execute();
  5. None of the above
Tests in PHP for Seniors

Test Name Difficulty Time (minutes) No. of Questions
PHP Online Test for Seniors PHP Senior 60 30

More Specific Tests in PHP for Seniors

Test Name Difficulty Time (Minutes) No. of Questions
PHP-Strings-and-Patterns Online Test for Seniors PHP - Strings and Patterns Senior 20 10
PHP-Datatypes-and-Format Online Test for Seniors PHP - Datatypes and Format Senior 20 10
PHP-Databases Online Test for Seniors PHP - Databases Senior 20 10
PHP-Web-Features Online Test for Seniors PHP - Web Features Senior 20 10
PHP-Language-Fundamentals Online Test for Seniors PHP - Language Fundamentals Senior 20 10