PHP code example of lincanbin / php-pdo-mysql-class
1. Go to this page and download the library: Download lincanbin/php-pdo-mysql-class 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/ */
$DB->query("SELECT * FROM fruit WHERE name=?", array($_GET['name']));
$DB->query("SELECT * FROM fruit WHERE name=".$_GET['name']);
$DB->query("SELECT * FROM fruit WHERE name=? and color=?",array('apple','red'));
$DB->query("SELECT * FROM fruit WHERE name=:name and color=:color",array('name'=>'apple','color'=>'red'));
Array
(
[0] => Array
(
[id] => 1
[name] => apple
[color] => red
)
)
$DB->query("SELECT * FROM fruit WHERE name IN (:fruits)",array(array('apple','banana')));
$query = "SELECT * FROM fruit WHERE name IN (:fruits) AND color = :color";
// use multidimensional array as $params
$params = array(
"color" => "red",
"fruits" => array(
"apple",
"banana"
)
);
$DB->query($query, $params);
Array
(
[0] => Array
(
[id] => 1
[name] => apple
[color] => red
)
)
$DB->column("SELECT color FROM fruit WHERE name IN (:color)",array('apple','banana','watermelon'));
Array
(
[0] => red
[1] => yellow
[2] => green
)
$DB->row("SELECT * FROM fruit WHERE name=? and color=?",array('apple','red'));
Array
(
[id] => 1
[name] => apple
[color] => red
)
$DB->single("SELECT color FROM fruit WHERE name=? ",array('watermelon'));
green
// Delete
$DB->query("DELETE FROM fruit WHERE id = :id", array("id"=>"1"));
$DB->query("DELETE FROM fruit WHERE id = ?", array("1"));
// Update
$DB->query("UPDATE fruit SET color = :color WHERE name = :name", array("name"=>"strawberry","color"=>"yellow"));
$DB->query("UPDATE fruit SET color = ? WHERE name = ?", array("yellow","strawberry"));
// Insert
$DB->query("INSERT INTO fruit(id,name,color) VALUES(?,?,?)", array(null,"mango","yellow"));//Parameters must be ordered
$DB->query("INSERT INTO fruit(id,name,color) VALUES(:id,:name,:color)", array("color"=>"yellow","name"=>"mango","id"=>null));//Parameters order free