Hoi allemaal,
Deze avond heb ik aan een klein projectje gewerkt. Namelijk een database engine als MySQL maar dan veel simpeler! Al je tabellen, data, etc gaat in 1 bestandje.
Hieronder toon ik hoe het allemaal werkt:
Database ophalen
Een tabel aanmaken
Een tabel verwijderen
Kolommen toevoegen/verwijderen
Dingen toevoegen aan een tabel
Alle data uit een tabel ophalen en manipuleren
Dat was het zon beetje! Heeft iemand hier interesse in? Zoja, dan release ik de bestanden.
Binnenkort voeg ik ook nog toe dat je dan ->where(name, =, Raoul) kan doen ofzo zodat je ook zo rijen kunt ophalen ipv ->all().
Raoul
Deze avond heb ik aan een klein projectje gewerkt. Namelijk een database engine als MySQL maar dan veel simpeler! Al je tabellen, data, etc gaat in 1 bestandje.
Hieronder toon ik hoe het allemaal werkt:
Database ophalen
[COLOR= #0000BB]<?php
$database[/COLOR] [COLOR= #007700]= new[/COLOR] Database[COLOR= #007700]([/COLOR][COLOR= #DD0000]database.db[/COLOR][COLOR= #007700]);[/COLOR] [COLOR= #FF8000]// "database.db" is de bestandsnaam.[/COLOR]
?> Een tabel aanmaken
[COLOR= #0000BB]<?php
$database[/COLOR][COLOR= #007700]->[/COLOR]addTable[COLOR= #007700]([/COLOR][COLOR= #DD0000]leden[/COLOR][COLOR= #007700],[/COLOR] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700]([/COLOR]
[COLOR= #DD0000]naam[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]leeftijd[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]wachtwoord[/COLOR]
[COLOR= #007700]));[/COLOR]
?> Een tabel verwijderen
[COLOR= #0000BB]<?php
$database[/COLOR][COLOR= #007700]->[/COLOR]getTable[COLOR= #007700]([/COLOR][COLOR= #DD0000]leden[/COLOR][COLOR= #007700])->[/COLOR]remove[COLOR= #007700]();[/COLOR]
?> Kolommen toevoegen/verwijderen
[COLOR= #0000BB]<?php
$t[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$database[/COLOR][COLOR= #007700]->[/COLOR]getTable[COLOR= #007700]([/COLOR][COLOR= #DD0000]leden[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$t[/COLOR][COLOR= #007700]->[/COLOR]addCollumn[COLOR= #007700]([/COLOR][COLOR= #DD0000]karma[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$t[/COLOR][COLOR= #007700]->[/COLOR]removeCollumn[COLOR= #007700]([/COLOR][COLOR= #DD0000]karma[/COLOR][COLOR= #007700]);[/COLOR]
?> Dingen toevoegen aan een tabel
[COLOR= #0000BB]<?php
$t[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$database[/COLOR][COLOR= #007700]->[/COLOR]getTable[COLOR= #007700]([/COLOR][COLOR= #DD0000]leden[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$t[/COLOR][COLOR= #007700]->[/COLOR]insert[COLOR= #007700]([/COLOR][URL="http://www.php.net/array"]array[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]Raoul[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]14[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]supergeheim[/COLOR][COLOR= #007700]));[/COLOR]
?> Alle data uit een tabel ophalen en manipuleren
[COLOR= #0000BB]<?php
$table[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$database[/COLOR][COLOR= #007700]->[/COLOR]getTable[COLOR= #007700]([/COLOR][COLOR= #DD0000]leden[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$alles[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #0000BB]$table[/COLOR][COLOR= #007700]->[/COLOR]all[COLOR= #007700]();[/COLOR] [COLOR= #FF8000]// Haal ALLE rijen op![/COLOR]
[URL="http://www.php.net/foreach"]foreach[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$alles[/COLOR] [COLOR= #007700]as[/COLOR] [COLOR= #0000BB]$lid[/COLOR][COLOR= #007700]) {[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$lid[/COLOR][COLOR= #007700]->[/COLOR]get[COLOR= #007700]([/COLOR][COLOR= #DD0000]naam[/COLOR][COLOR= #007700]) .[/COLOR] [COLOR= #DD0000] is [/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$lid[/COLOR][COLOR= #007700]->[/COLOR]get[COLOR= #007700]([/COLOR][COLOR= #DD0000]leeftijd[/COLOR][COLOR= #007700]) .[/COLOR] [COLOR= #DD0000] jaar oud.[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$lid[/COLOR][COLOR= #007700]->[/COLOR]set[COLOR= #007700]([/COLOR][COLOR= #DD0000]naam[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]Henk[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]De naam van het lid is veranderd naar Henk![/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$lid[/COLOR][COLOR= #007700]->[/COLOR]remove[COLOR= #007700]();[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Het lid is nu verwijderd![/COLOR][COLOR= #007700];
}[/COLOR]
?> Dat was het zon beetje! Heeft iemand hier interesse in? Zoja, dan release ik de bestanden.
Binnenkort voeg ik ook nog toe dat je dan ->where(name, =, Raoul) kan doen ofzo zodat je ook zo rijen kunt ophalen ipv ->all().
Raoul

