added foreign key to database

php
Marc Wäckerlin 9 years ago
parent f11d2c7c56
commit d5dd8200b9
  1. 6
      html/messagetable.php
  2. 11
      html/safechat.js
  3. 4
      html/usertable.php

@ -12,9 +12,9 @@
<table>
<caption>Table: message</caption>
<tr><th>Colum Name</th><th>SQL Type</th><th>Description</th></tr>
<tr><td>id</td><td>int</td><td>Incrementing message id starting at 1.</td></tr>
<tr><td>id</td><td>int, primary key</td><td>Incrementing message id starting at 1.</td></tr>
<tr><td>time</td><td>timestamp</td><td>Time when message has been stored in the database.</td></tr>
<tr><td>user</td><td>varchar(50)</td><td>The sender's user name (pseudonym).</td></tr>
<tr><td>user</td><td>varchar(50), references \ref usertable "user (name)"</td><td>The sender's user name (pseudonym).</td></tr>
<tr><td>msg</td><td>longtext</td><td>The encryped and armored message text.</td></tr>
</table>
*/
@ -23,7 +23,7 @@
require_once("opendb.php");
try {
$db->query('create table if not exists message (id int primary key not null auto_increment, time timestamp default current_timestamp, user varchar(50) not null, msg longtext not null);');
$db->query('create table if not exists message (id int primary key not null auto_increment, time timestamp default current_timestamp, user varchar(50) not null, msg longtext not null, foreign key (user) references user(name) on delete cascade on update cascade) character set utf8 engine=innodb;');
$db->query('set global max_allowed_packet=1000000000');
$db->query('set global net_buffer_length=1000000');
} catch (Exception $e) {

@ -686,4 +686,13 @@ function start() {
}
/// On Load, Call @ref start
$(start);
$(
window.onbeforeunload = function() {
return "Are you sure you want to navigate away?";
}
window.onunload = function () { // you probably don't want to leave now...
alert('You are trying to leave.');
return false;
}
start();
);

@ -14,7 +14,7 @@
<table>
<caption>Table: user</caption>
<tr><th>Colum Name</th><th>SQL Type</th><th>Description</th></tr>
<tr><td>name</td><td>varchar(50)</td><td>The user's name (pseudonym).</td></tr>
<tr><td>name</td><td>varchar(50), primary key</td><td>The user's name (pseudonym).</td></tr>
<tr><td>pubkey</td><td>text</td><td>The user's public key.</td></tr>
</table>
@ -24,7 +24,7 @@
require_once("opendb.php");
try {
$db->query('create table if not exists user (name varchar(50) not null unique key, pubkey text not null);');
$db->query('create table if not exists user (name varchar(50) not null primary key, pubkey text not null) character set utf8 engine=innodb;');
} catch (Exception $e) {
error('database error on server');
}

Loading…
Cancel
Save