Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*****************/
- /* Gets one row. */
- /*****************/
- // Global the object.
- global $board1_db;
- // SQL query. Replace all parameters with question marks (that's how PDO does it).
- $sql = 'SELECT member_name, email_address
- FROM {db_prefix}members
- WHERE id_member = ?;';
- // Array or parameters. Params must have the same number, and order as question marks in the the SQL.
- /**
- * $param_array = array(
- * $identifier => $value,
- * );
- */
- $param = array(
- 1 => 1,
- );
- // Assign a variable to the data returned from the function.
- $myid = $board1_db->getone($sql, $param);
- /**
- * Array
- * (
- * [member_name] => Mace Windu
- * [0] => Mace Windu
- * )
- * 1
- */
- $member = array(
- 'name' => $myid['member_name'],
- 'email' => $myid['email_address'],
- );
- /*****************/
- /* Get all rows. */
- /*****************/
- global $board1_db;
- $sql = 'SELECT member_name, email_address
- FROM {db_prefix}members
- WHERE id_member < ?;';
- $param = array(
- 1 => 0,
- );
- $users_query = $board1_db->getall($sql, $params);
- /*
- Array
- (
- [0] => Array
- (
- [member_name] => Mace Windu
- [0] => Mace Windu
- [email_address] => m4ce.windu@gmail.com
- [1] => m4ce.windu@gmail.com
- )
- [1] => Array
- (
- [member_name] => someone
- [0] => someone
- [email_address] => fake@fake.com
- [1] => fake@fake.com
- )
- )
- 1
- */
- $users = array();
- foreach ($users_query as $userq)
- {
- $users = array(
- 'name' => $userq['member_name'],
- 'email' => $userq['email_address'],
- );
- }
- /*****************************/
- /* Perform and action. W00t! */
- /*****************************/
- $sql = 'INSERT INTO {db_prefix}members (member_name, email_address)
- VALUES (?, ?);';
- $params = array(
- 1 => 'new_user',
- 2 => 'fake_email@fake.com',
- );
- $board1_db->action($sql, $params);
- /*
- * Returns true if no errors.
- */
Add Comment
Please, Sign In to add comment