Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function store_data($data) {
- $dsn = 'mysql:host=localhost;dbname=mydatabase';
- $username = 'myusername';
- $password = 'mypassword';
- $options = array(
- PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
- );
- try {
- $pdo = new PDO($dsn, $username, $password, $options);
- $pdo->beginTransaction();
- $stmt = $pdo->prepare('INSERT INTO data_storage (value) VALUES (:value)');
- foreach ($data as $value) {
- $stmt->bindParam(':value', $value);
- $stmt->execute();
- }
- $pdo->commit();
- } catch (PDOException $e) {
- $pdo->rollBack();
- throw $e;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement