-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo02.php
executable file
·52 lines (44 loc) · 1.18 KB
/
demo02.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/**
* Created by JetBrains PhpStorm.
* User: christiannielebock
* Date: 03.09.13
* Time: 13:45
* To change this template use File | Settings | File Templates.
*/
/**
* include RedBeanPHP
*/
require("lib/rb.php");
/**
* setup RedBeanPHP
*/
try {
R::setup('mysql:host=localhost;dbname=redbean_demo', 'redbean', 'redbean');
echo "Database connection successful.";
} catch (Exception $e) {
echo "Error while connection to the database: " . $e->getMessage();
}
/**
* Simple Crud - option 1
*/
$ugMember = R::dispense('member');
$ugMember->foreName = "Christian";
$ugMember->lastName = "Nielebock";
$ugMember->mailAddress = "[email protected]";
$ugMemberID = R::store($ugMember);
echo "<br/><br/>";
echo "ugMemberID of " . $ugMember->foreName . " = " . $ugMemberID . "<br/>";
/**
* Simple Crud - option 2
*/
$anotherMember = R::dispense('member');
$anotherMember->setAttr('foreName', 'Andreas')
->setAttr('lastName', 'Heigl')
->setAttr('mailAddress', '[email protected]');
$anotherMemberID = R::store($anotherMember);
echo "ugMemberID of " . $anotherMember->foreName . " = " . $anotherMemberID . "<br/>";
/**
* close db handle
*/
R::close();