PHP code example of samayo / styrofoam

1. Go to this page and download the library: Download samayo/styrofoam library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

samayo / styrofoam example snippets




$db = new Styrofoam\Database(
  'mysql:host=localhost; dbname=db-name;  charset=utf8', 'db-user', 'db-pass', [
  PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
  PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC 
]);

// returns $select with value of query
$select = $db->select('SELECT * FROM users WHERE id = ?', [145]);

// returns value lastInsertId() on success
$insert = $db->insert('INSERT INTO users (lastname) VALUES (?)', ['robin']);

// returns $delete as boolean
$delete = $db->delete('DELETE FROM users WHERE id = ?', [456]);

// returns $update as boolean
$update = $db->update('UPDATE cars SET color = ? WHERE model = ?', ['blue', 'Toyota']);