Difference between revisions of "Database Programmering"
From Teknologisk videncenter
Line 6: | Line 6: | ||
En side til oprettelse af brugere | En side til oprettelse af brugere | ||
En side til at verificere et login | En side til at verificere et login | ||
+ | Et backup system i json | ||
+ | |||
+ | ==Eksempler== | ||
+ | JSON | ||
+ | <source lang="php"> | ||
+ | <?php | ||
+ | class MyClass { | ||
+ | public $name = "Mads"; | ||
+ | public $age = 27; | ||
+ | public $awesome = TRUE; | ||
+ | } | ||
+ | |||
+ | $mads = new MyClass(); | ||
+ | $json = json_encode($mads); | ||
+ | //{"name":"Mads","age":27,"awesome":true} | ||
+ | |||
+ | $newMads = json_decode($json); | ||
+ | echo $newMads->$name; | ||
+ | ?> | ||
+ | </source> | ||
+ | |||
+ | Saving a File (simple) | ||
+ | <source lang="php"> | ||
+ | <?php | ||
+ | file_put_contents("myFile.txt", "PHP is used for Server-Side Applications"); | ||
+ | echo file_get_contents("myFile.txt"); | ||
+ | ?> | ||
+ | </source> | ||
+ | |||
+ | Saving a File (full) | ||
+ | <source lang="php"> | ||
+ | <?php | ||
+ | $filename = "myFile.txt"; | ||
+ | $handle = fopen($filename, 'w'); | ||
+ | fwrite($handle, "Now we have far more control!"); | ||
+ | fclose($handle); | ||
+ | $handle = fopen($filename, 'r'); | ||
+ | echo "File Says:\n"; | ||
+ | echo fread($handle, filesize($filename)); | ||
+ | fclose($handle); | ||
+ | ?> | ||
+ | </source> |
Revision as of 10:24, 5 December 2017
Forberedelse til Mandag
Hav XAMPP klar på jeres computer. XAMPP kan downloades her https://www.apachefriends.org/index.html
Opgave
Bruger Database (navn og password) En side til oprettelse af brugere En side til at verificere et login Et backup system i json
Eksempler
JSON
<?php
class MyClass {
public $name = "Mads";
public $age = 27;
public $awesome = TRUE;
}
$mads = new MyClass();
$json = json_encode($mads);
//{"name":"Mads","age":27,"awesome":true}
$newMads = json_decode($json);
echo $newMads->$name;
?>
Saving a File (simple)
<?php
file_put_contents("myFile.txt", "PHP is used for Server-Side Applications");
echo file_get_contents("myFile.txt");
?>
Saving a File (full)
<?php
$filename = "myFile.txt";
$handle = fopen($filename, 'w');
fwrite($handle, "Now we have far more control!");
fclose($handle);
$handle = fopen($filename, 'r');
echo "File Says:\n";
echo fread($handle, filesize($filename));
fclose($handle);
?>