Guest User

Untitled

a guest
Feb 11th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. $tag = array('item1', 'item2', 'item3');
  2.  
  3. // Prepare a query for execution
  4. $result = pg_prepare($dbconn, "my_query", "INSERT INTO $table ($column) VALUES ($1)");
  5.  
  6. // Execute the prepared query. Note that it is not necessary to escape
  7. // the string "Joe's Widgets" in any way
  8. $result = pg_execute($dbconn, "my_query", array("$tag"));
  9.  
  10. $tag = array('item1', 'item2', 'item3');
  11.  
  12. // Prepare a query for execution
  13. $result = pg_prepare($dbconn, "my_query", "INSERT INTO $table ($column) VALUES ($1)");
  14.  
  15. // Execute the prepared query. Note that it is not necessary to escape
  16. // the string "Joe's Widgets" in any way
  17. foreach( $tag as $i )
  18. $result = pg_execute($dbconn, "my_query", array($i));
  19. /// alternatively you could try this if you really wanna insert a text as array of text without using text[] type - uncomment line below and comment the 2 above
  20. // $result = pg_execute($dbconn, "my_query", array(json_encode($tag)));
  21.  
  22. $tag = array('item1', 'item2', 'item3');
  23.  
  24. // Prepare a query for execution
  25. $result = pg_prepare($dbconn, "my_query", "INSERT INTO $table ($column) VALUES ($1)");
  26.  
  27. // Execute the prepared query. Note that it is not necessary to escape
  28. // the string "Joe's Widgets" in any way
  29. $tmp = json_encode($tag);
  30. $tmp[0] = '{';
  31. $tmp[strlen($tmp) - 1] = '}';
  32. $result = pg_execute($dbconn, "my_query", array($tmp));
  33.  
  34. $tag = array('item1', 'item2', 'item3');
  35. $tag = serialize($tag);
  36. // Prepare a query for execution
  37. $result = pg_prepare($dbconn, "my_query", "INSERT INTO $table ($column) VALUES ($1)");
  38.  
  39. // Execute the prepared query. Note that it is not necessary to escape
  40. // the string "Joe's Widgets" in any way
  41. $result = pg_execute($dbconn, "my_query", $tag);
Add Comment
Please, Sign In to add comment