Show sourcecode
The following files exists in this folder. Click to view.
webbsrvprg/webbsrvprg/exercises/PHPDB/ovn1/
createkompisar.php
delete_post_ovn1.php
insert_into_table_ovn1.php
insertintotable_default2.php
post_actions_ovn1.php
selectpost2.php
update_post_ovn1.php
selectpost2.php
68 lines ASCII Windows (CRLF)
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Select</title>
</head>
<body>
<?php
include ('../dbconnect.php');
try {
/*** The SQL SELECT statement ***/
$sql = "SELECT * FROM kompisar";
$stmt = $dbconn->prepare($sql);
// parameters in array, if empty we could skip the $data-variable
$data = array();
$stmt->execute($data);
$res = $stmt->fetchAll();
$output = htmlentities(print_r($res, 1));
echo "<pre>$output</pre>";
// fetch width column names
$data = array();
$stmt->execute($data);
$res = $stmt->fetch(PDO::FETCH_ASSOC);
$output = htmlentities(print_r($res, 1));
echo "<pre>$output</pre>";
// fetch columnindex
$data = array();
$stmt->execute($data);
$res = $stmt->fetch(PDO::FETCH_NUM);
$output = htmlentities(print_r($res, 1));
echo "<pre>$output</pre>";
// fetch width column names, create a table
$data = array();
$stmt->execute($data);
$output = "<table><caption>En ostylad tabell!</caption>";
while ($res = $stmt->fetch(PDO::FETCH_ASSOC)) {
$output .= "<tr>".
"<td>".htmlentities($res['id'])."</td>".
"<td>".htmlentities($res['firstname'])."</td>".
"<td>".htmlentities($res['lastname'])."</td>".
"<td>".htmlentities($res['phone'])."</td>".
"<td>".htmlentities($res['email'])."</td>".
"<td>".htmlentities($res['reg_date'])."</td>".
"</tr>";
}
$output .= "</table>";
echo "$output";
}
catch(PDOException $e)
{
echo $sql . "<br />" . $e->getMessage();
}
$dbconn = null;
?>
<a href="post_actions_ovn1.php"><button class="link">
Post actions
</button></a>
</body>
</html>