bind_rowid.phpt 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. --TEST--
  2. Test ROWID bind
  3. --EXTENSIONS--
  4. oci8
  5. --FILE--
  6. <?php
  7. require(__DIR__."/connect.inc");
  8. function do_query($c)
  9. {
  10. $s = oci_parse($c, 'select address from rid_tab order by id');
  11. $id = 1;
  12. oci_execute($s, OCI_DEFAULT);
  13. while ($row = oci_fetch_array($s, OCI_ASSOC+OCI_RETURN_NULLS)) {
  14. var_dump($row);
  15. }
  16. }
  17. $stmtarray = array(
  18. "drop table rid_tab",
  19. "create table rid_tab (id number, address varchar2(40))",
  20. "insert into rid_tab (id, address) values (1, 'original text #1')",
  21. "insert into rid_tab (id, address) values (2, 'original text #2')"
  22. );
  23. oci8_test_sql_execute($c, $stmtarray);
  24. echo "Initial Data\n";
  25. do_query($c);
  26. $s = oci_parse($c, 'select rowid, address from rid_tab where id = :l_bv for update');
  27. $id = 1;
  28. oci_bind_by_name($s, ':l_bv', $id);
  29. oci_execute($s, OCI_DEFAULT);
  30. $row = oci_fetch_array($s, OCI_ASSOC+OCI_RETURN_NULLS);
  31. $rid = $row['ROWID'];
  32. $addr = $row['ADDRESS'];
  33. $addr = 'Some new text';
  34. // Save changes
  35. $s = oci_parse($c,'update rid_tab set address = :a_bv where rowid = :r_bv');
  36. oci_bind_by_name($s, ':r_bv', $rid, -1, OCI_B_ROWID);
  37. oci_bind_by_name($s, ':a_bv', $addr);
  38. oci_execute($s);
  39. echo "Verify Change\n";
  40. do_query($c);
  41. // Cleanup
  42. $stmtarray = array(
  43. "drop table rid_tab"
  44. );
  45. oci8_test_sql_execute($c, $stmtarray);
  46. echo "Done\n";
  47. ?>
  48. --EXPECT--
  49. Initial Data
  50. array(1) {
  51. ["ADDRESS"]=>
  52. string(16) "original text #1"
  53. }
  54. array(1) {
  55. ["ADDRESS"]=>
  56. string(16) "original text #2"
  57. }
  58. Verify Change
  59. array(1) {
  60. ["ADDRESS"]=>
  61. string(13) "Some new text"
  62. }
  63. array(1) {
  64. ["ADDRESS"]=>
  65. string(16) "original text #2"
  66. }
  67. Done