Guest User

Untitled

a guest
Oct 22nd, 2017
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.93 KB | None | 0 0
  1. /*****************/
  2. /* Gets one row. */
  3. /*****************/
  4.  
  5. // Global the object.
  6. global $board1_db;
  7.  
  8. // SQL query. Replace all parameters with question marks (that's how PDO does it).
  9. $sql = 'SELECT member_name, email_address
  10. FROM {db_prefix}members
  11. WHERE id_member = ?;';
  12.  
  13. // Array or parameters. Params must have the same number, and order as question marks in the the SQL.
  14. /**
  15. * $param_array = array(
  16. *   $identifier => $value,
  17. * );
  18. */
  19. $param = array(
  20.     1 => 1,
  21. );
  22.  
  23. // Assign a variable to the data returned from the function.   
  24. $myid = $board1_db->getone($sql, $param);
  25.  
  26. /**
  27. * Array
  28. * (
  29. *     [member_name] => Mace Windu
  30. *     [0] => Mace Windu
  31. * )
  32. * 1
  33. */
  34.  
  35. $member = array(
  36.     'name' => $myid['member_name'],
  37.     'email' => $myid['email_address'],
  38. );
  39.  
  40. /*****************/
  41. /* Get all rows. */
  42. /*****************/
  43.  
  44. global $board1_db;
  45.  
  46. $sql = 'SELECT member_name, email_address
  47. FROM {db_prefix}members
  48. WHERE id_member < ?;';
  49.  
  50. $param = array(
  51.     1 => 0,
  52. );
  53.  
  54. $users_query = $board1_db->getall($sql, $params);
  55.  
  56. /*
  57. Array
  58. (
  59.     [0] => Array
  60.         (
  61.             [member_name] => Mace Windu
  62.             [0] => Mace Windu
  63.             [email_address] => m4ce.windu@gmail.com
  64.             [1] => m4ce.windu@gmail.com
  65.         )
  66.  
  67.     [1] => Array
  68.         (
  69.             [member_name] => someone
  70.             [0] => someone
  71.             [email_address] => fake@fake.com
  72.             [1] => fake@fake.com
  73.         )
  74.  
  75. )
  76. 1
  77. */
  78.  
  79. $users = array();
  80. foreach ($users_query as $userq)
  81. {
  82.     $users = array(
  83.         'name' => $userq['member_name'],
  84.         'email' => $userq['email_address'],
  85.     );
  86. }
  87.  
  88. /*****************************/
  89. /* Perform and action. W00t! */
  90. /*****************************/
  91.  
  92. $sql = 'INSERT INTO {db_prefix}members (member_name, email_address)
  93. VALUES (?, ?);';
  94.  
  95. $params = array(
  96.     1 => 'new_user',
  97.     2 => 'fake_email@fake.com',
  98. );
  99.  
  100. $board1_db->action($sql, $params);
  101.  
  102. /*
  103. * Returns true if no errors.
  104. */
Add Comment
Please, Sign In to add comment