Inserting large objects in PHP (ibm_db2)
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.
Before you begin
Obtain a connection resource by calling one of the connection functions in the ibm_db2 API.
Procedure
To insert a large object into the database directly from a file:
- Call the db2_prepare function to prepare an INSERT statement with a parameter marker that represents the large object column.
- Set the value of a PHP variable to the path and name of the file that contains the data for the large object. The path can be relative or absolute, and is subject to the access permissions of the PHP executable file.
- Call the db2_bind_param function to bind the parameter marker to the variable. The third argument to this function is a string representing the name of the PHP variable that holds the path and name of the file. The fourth argument is DB2_PARAM_FILE, which tells the ibm_db2 extension to retrieve the data from a file.
- Call the db2_execute function to issue the INSERT statement.
Example
Insert a large object into the database.
$stmt = db2_prepare($conn, "INSERT INTO animal_pictures(picture) VALUES (?)");
$picture = "/opt/albums/spook/grooming.jpg";
$rc = db2_bind_param($stmt, 1, "picture", DB2_PARAM_FILE);
$rc = db2_execute($stmt);