static function delete($arr, $multi = '') { if ($arr) { if ($multi) { foreach ($arr as $i => $a) { $delete[] = array("table" => self::$table, "where" => array("id" => $i)); } } else { $delete[] = array("table" => self::$table, "where" => array("id" => $arr)); } $json_delete = json_encode($delete); return parent::execute('delete:' . $json_delete); } }
/** * Main method * * */ public function __construct() { // Validates the form input submitted, before writing to database if ($_POST) { $firstName = filter_input(INPUT_POST, 'firstname', FILTER_SANITIZE_STRING); $lastName = filter_input(INPUT_POST, 'lastname', FILTER_SANITIZE_STRING); $mail = filter_input(INPUT_POST, 'mail', FILTER_VALIDATE_EMAIL); // Performing validation if (empty($firstName) || empty($lastName)) { $error = 'Enter your name and last name'; } else { if (isset($_POST['mail']) && !empty($_POST['mail']) && $mail == FALSE) { $error = 'Enter a valid email address'; } } // Displays a message in case of errors if (isset($error)) { self::$message = '<i style="color: #f50;">ERROR: ' . $error . '</i><br /><br />'; } else { // SQL insertion in JSON format $json = ' insert : [ { table: "users" , values: { firstname: "' . $firstName . '", lastname: "' . $lastName . '", mail: "' . $mail . '" } } ] '; // Performs the new record and store the result list($total) = PDO4You::execute($json); // Displays a success message self::$message = 'Register #' . $total . ' added successfully!!<br /><br />'; } } // Capture records of all registered users self::$hasRecords = PDO4You::select('SELECT * FROM users ORDER BY id DESC'); }
<?php // Loading demo class require 'DemoCRUD.php'; // Example with Multiple Instances echo '<h2><a href=".">DEMOS</a> › MULTIPLE INSTANCES</h2>'; // Importing classes use PDO4You\PDO4You; // Creating an instance $demo = new DemoCRUD(); // Displaying records of the default instance "standard" $demo->select(); PDO4You::getInstance('bookstore', 'sqlite:data/database_bookstore.db'); PDO4You::getInstance('pdo4you', 'sqlite:data/database_pdo4you.db'); // Displaying records from the data instance: bookstore $demo->select('bookstore'); // Displaying records from the data instance: pdo4you $demo->select('pdo4you'); // Sets another instance PDO4You::setInstance('standard'); #PDO4You::setInstance('bookstore'); // Displaying records from the last data instance set $demo->select();
<?php // Loading all the necessary files require __DIR__ . '/src/bootstrap.php'; // Connection class imported use PDO4You\PDO4You; // Connection instance started and available PDO4You::getInstance(); // Applying styling on the page PDO4You::css(); // Displaying details on the target server's database connected PDO4You::showServerInfo(); ?> <!doctype html> <html> <head> <meta charset="UTF-8" /> <title>PDO4You</title> <style> body { background:#FAFAFA; font:normal 12px/1.7em Bitstream Vera Sans Mono,Courier New,Monospace; margin:0; padding:0; } a { color:#08C; text-decoration:none; } b { color:#CCC; } #pdo4you h2 { color:#000; background:#FFF; font-size:20px; display:block; margin:0; padding:10px; border-bottom:solid 1px #999; } .pagination { margin-top:25px;} .pagination a { color:#08C; background:#FFF; border:1px solid #BBB; font-size:12px; font-weight:bold; display:inline-block; min-width:13px; min-height:15px; margin:0 2px; padding:1px 6px; -webkit-border-radius:2px; -moz-border-radius:2px; border-radius:2px; text-align:center; cursor:pointer; } .pagination a.selected, .pagination a.selected:hover, .pagination a:hover { color:#FFF; background:#09E; border:1px solid #08C; } .pagination a.nolink, .pagination a.nolink:hover { color:#AAA; background:#FFF; border:1px solid #CCC; cursor:default; } </style> </head> <body id="pdo4you"> <?php if ((string) ($page = filter_input(INPUT_GET, 'p'))) {
public function testMultipleInsertInArrayFormat() { $array['query'] = array(array('table' => 'users', 'values' => array('firstname' => "John", 'lastname' => "Lennon")), array('table' => 'users', 'values' => array('firstname' => "Paul", 'lastname' => "McCartney"))); // Executes the SQL and stores the result $result = test::insert($array); $this->assertEquals(2, self::getNumRowsAffected($result), 'Test with Insert method'); }
/** * Format the Result * */ private function getResult($result, $show_lastid = false) { $result = '<br /><br /> - The code above will output: <pre style="color:blue;">' . print_r($this->sanitize($result), true) . '</pre>'; $result .= 'Total records affected: <strong style="color:red;">' . PDO4You::rowCount() . '</strong>'; $result .= $show_lastid ? ' Id of the last iteration: <strong style="color:red;">' . PDO4You::lastId() . '</strong>' : null; return $result; }