PHP script to update an IBM i physical file
PHP script to update an IBM i physical file
I am writing a PHP script to update a single record in a PF on our IBM i (AS/400). I will be updating several (but not all) columns in the record. What is the safest and most efficient approach? Should I concatenate a string together with the variable names to create an SQL update query and use db2_prepare? Should I use an array to provide the data for the SQL update query? Can I use db2_bind_param with an update query? Can someone suggest an approach and help me with the syntax? Thanks, Pat
-
- Posts: 187
- Joined: Wed Apr 22, 2009 2:29 pm
- Location: Edmonton, AB, Canada
Re: PHP script to update an IBM i physical file
The safest would be to use db2_prepare with parameter markers. So create your SQL update statement (dynamically if you are not always updating all of the fields)
Build your array of parameters:
Prepare and execute the query with db2_prepare and db2_execute:
I have the prepare and execute in a class that I can reuse so if I want/need to make any changes to the database access it can be done in a single spot.
Hope that helps.
Scott
Code: Select all
$sql = "UPDATE SOMELIB.SOMEFILE SET COL1=?,COL2=?,COL3=? WHERE KEY = ?"
Code: Select all
$parms = array($col1,$col2,$col3,$key);
Code: Select all
// You would also want some error checking in here
$query_res = db2_prepare ( $conn, $sql);
$qry_err = db2_execute ( $query_res, $parms );
// Check how many rows were affected
$rows = db2_num_rows ( $query_res );
Hope that helps.
Scott
Re: PHP script to update an IBM i physical file
Scott,
Yes, that is a big help. Thanks.
Yes, that is a big help. Thanks.
Re: PHP script to update an IBM i physical file
How much PHP language is effective for solving various problems?