When you insert a large object into the database, rather
than loading all of the data for a large object into a PHP string
and passing it to the IBM data
server database through an INSERT statement, you can insert large
objects directly from a file on your PHP server.
Procedure
To insert a large object into the database directly from
a file:
- Call the PDO::prepare method to create
a PDOStatement object from an INSERT statement with a parameter marker
that represents the large object column.
- Create a PHP variable that represents a stream (for example,
by assigning the value returned by the fopen function
to variable).
- Call the PDOStatement::bindParam method,
passing the listed arguments to bind the parameter marker to the PHP
variable that represents the stream of data for the large object:
- parameter
- A parameter identifier. For question mark parameter markers (?),
this is an integer that represents the 1-indexed position of the parameter
in the SQL statement. For named parameter markers (:name),
this is a string that represents the parameter name.
- variable
- The value to use in place of the parameter marker
- data_type
- The PHP constant, PDO::PARAM_LOB, which tells
the PDO extension to retrieve the data from a file.
- Call the PDOStatement::execute method
to issue the INSERT statement.
Example
Insert a large object into the database.
$stmt = $conn->prepare("INSERT INTO animal_pictures(picture) VALUES (?)");
$picture = fopen("/opt/albums/spook/grooming.jpg", "rb");
$stmt->bindParam(1, $picture, PDO::PARAM_LOB);
$stmt->execute();