php-Framework fuer html Formulare mit datenbank backend …
Phormation set up
Installation der Files in z.B. /usr/lib/phormation.
global.php
< ?
DEFINE( "PHORMATIONDIR", "/usr/lib/phormation" );
DEFINE( "PHORMATIONIMAGEDIR", "/var/www/phormationimage" );
$DB = "mysql";
$DATABASE = "people";
?>
|
Datenbank set up
Datenbank und Tabelle erzeugen mysql -p < db.sql
db.sql
CREATE DATABASE IF NOT EXISTS people;
use people;
DROP TABLE names;
CREATE TABLE names (
id int auto_increment not null,
firstname varchar(50),
lastname varchar(50),
primary key( id )
);
|
Die Datenbankverbindung muss in der Variablen $conn gespeichert werden:
dbconnect.php
< ?
$conn = mysql_connect("host", "name", "passwort");
if( !$conn ) {
echo "Couldn't connect to database!";
}
$dbs = mysql_select_db($DATABASE,$conn);
if( !$dbs ) {
echo "Couldn't connect to database $DATABASE !";
}
? >
|
Index
< ?
include_once("global.php");
include_once("dbconnect.php");
include_once( PHORMATIONDIR . "/displaytable.php");
// html vor der Tabelle
function html_before_table() {
<html>
<head>
<link rel="stylesheet" type="text/css" href="styles.css">
<title>Tolles Formular</title>
</head>
<body>
<h1>Tabellet</h1>
}
// html nach der Tabelle
function html_after_table() {
</body>
</html>
}
// Felder
$fields[] = "firstname"; $name[] = "Vorname";
$fields[] = "lastname"; $name[] = "Nachname";
// notwendige Parameter
$params["query"] = "SELECT * FROM $DATABASE.names";
$param["defaultsort"] = "lastname";
$param["editlink"] = "editButtonLink.php";
$param["newlink"] = "newButtonLink.php";
$param["delquery"] = "DELETE FROM $DATEBASE.names WHERE id= ";
$param["key"] = "id";
// Tabelle
table_index( $fields, $names, $params );
? >
|
Formular
< ?
include_once("global.php");
include_once("dbconnect.php");
include_once( PHORMATIONDIR . "/form.php");
// html vor dem Formular
function html_before_form() {
<html>
<head>
<link rel="stylesheet" type="text/css" href="styles.css">
<title>Tolles Formular</title>
</head>
<body>
<h1>Formular</h1>
}
// html nach dem Formular
function html_after_form() {
</body>
</html>
}
// Formularfelder
$fields[] = "firstname";
$name[] = "Vorname";
$types[] = "type=text&width=22&length=40&required=1";
$fields[] = "lastname";
$name[] = "Nachname";
$types[] = "type=text&width=22&length=40&required=1";
// Formular
form_main( "people.names", "id", $fields, $names, $types, $record_id, $url, $opts );
? >
|
Sag etwas dazu: