PHP code example of xsuchy09 / e_pdostatement
1. Go to this page and download the library: Download xsuchy09/e_pdostatement 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/ */
xsuchy09 / e_pdostatement example snippets
$content = $_POST['content'];
$title = $_POST['title'];
$date = date('Y-m-d');
$query = 'INSERT INTO posts SET content = :content, title = :title, date = :date';
$stmt = $pdo->prepare($query);
$stmt->bindParam(':content', $content, PDO::PARAM_STR);
$stmt->bindParam(':title' , $title , PDO::PARAM_STR);
$stmt->bindParam(':date' , $date , PDO::PARAM_STR);
$stmt->execute();
echo $stmt->fullQuery;
$query = 'INSERT INTO posts SET content = ?, title = ?, date = ?';
...
$stmt->bindParam(1, $content, PDO::PARAM_STR);
$stmt->bindParam(2, $title , PDO::PARAM_STR);
$stmt->bindParam(3, $date , PDO::PARAM_STR);
$query = 'INSERT INTO posts SET content = ?, title = ?, date = ?';
...
$params = [$content, $title, $date];
$stmt->execute($params);
$query = 'INSERT INTO posts SET content = :content, title = :title, date = :date';
...
$params = array(
':content' => $content,
':title' => $title,
':date' => $date,
);
$stmt->execute($params);
$content = $_POST['content'];
$title = $_POST['title'];
$date = date('Y-m-d');
$query = 'INSERT INTO posts SET content = :content, title = :title, date = :date';
$stmt = $pdo->prepare($query);
$stmt->bindParam(':content', $content, PDO::PARAM_STR);
$stmt->bindParam(':title' , $title , PDO::PARAM_STR);
$stmt->bindParam(':date' , $date , PDO::PARAM_STR);
$fullQuery = $stmt->interpolateQuery();
$content = $_POST['content'];
$title = $_POST['title'];
$date = date('Y-m-d');
$query = 'INSERT INTO posts SET content = ?, title = ?, date = ?';
$stmt = $pdo->prepare($query);
$params = [
$content,
$title,
$date
];
$fullQuery = $stmt->interpolateQuery($params);
/**
* -- OR --
*
* ql:host=localhost;dbname=myDatabase';
$pdo = new PDO($dsn, $dbUsername, $dbPassword);
$pdo->setAttribute(PDO::ATTR_STATEMENT_CLASS, ['EPDOStatement\EPDOStatement', [$pdo]]);
//$pdo->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('EPDOStatement\EPDOStatement', array($pdo))); // older php versions