Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- CREATE DATABASE talin;
- USE talin;
- CREATE TABLE t2 (a varchar(8), b date, c int);
- */
- function db_error($action, $error) {
- printf("%s failed: %s\n", $action, $error);
- exit();
- }
- $timestamp = DateTime::createFromFormat('d/m/Y','1/1/2021');
- $iso_date = $timestamp->format('Y-m-d');
- $db = new mysqli('localhost', 'talin', 'talin_password', 'talin');
- if(mysqli_connect_errno())
- db_error('Connect', $db->error);
- $query = "INSERT INTO t1(a, b, c) VALUES(?, ?, ?)";
- $stmt = $db->prepare($query);
- if(!$stmt)
- db_error('Prepare', $db->error);
- $a = 'text';
- $b = $iso_date;
- $c = 0;
- $bound = $stmt->bind_param('ssi', $a, $b, $c);
- if(!$bound)
- db_error('Bind', $db->error);
- $executed = $stmt->execute();
- if(!$executed)
- db_error('Execute', $db->error);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement