Show sourcecode
The following files exists in this folder. Click to view.
createtable.php
dbconnection.php
deletepost.php
deletetable.php
insertdefaultposts.php
insertpost.php
selectposts.php
updatepost.php
insertdefaultposts.php
50 lines UTF-8 Windows (CRLF)
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Namnlöst dokument</title>
</head>
<body>
<?php
include ('dbconnection.php');
try {
$sql = "INSERT INTO pdodemotable (firstname, lastname, age, reg_date)
VALUES ('Kalle', 'Anka', 120, now())";
// use exec() because no results are returned
$dbconn->exec($sql);
/*** prepare the SQL statement ***/
$sql = "INSERT INTO pdodemotable (firstname, lastname, age, reg_date)
VALUES ('Åsa', 'Anka', 110, now())";
$stmt = $dbconn->prepare($sql);
/*** execute the prepared statement ***/
$stmt->execute();
# sql
$sql = "INSERT INTO pdodemotable (firstname, lastname, age, reg_date)
VALUES (?, ?, ?, now())";
# prepare
$stmt = $dbconn->prepare($sql);
# the data we want to insert
$data = array('Östen', 'Anka', 90);
# execute width array-parameter
$stmt->execute($data);
$data = array('Amanda', 'Anka', 800);
$stmt->execute($data);
$data = array('Per', 'Anka', 70);
$stmt->execute($data);
echo "New records created successfully";
}
catch(PDOException $e)
{
echo $sql . "<br>" . $e->getMessage();
}
$dbconn = null;
?>
</body>
</html>