diff options
author | Erich Eckner <git@eckner.net> | 2022-07-28 10:55:13 +0200 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2022-07-28 10:55:13 +0200 |
commit | 33139b8aea2ee78f5f111679761d16bc821a802c (patch) | |
tree | 638e60453e20b4147d40c3bed7d8d21df0078f2a /html/db.php | |
parent | 703b60ed3ca3fb1653c008d42fd2dcf481b72927 (diff) | |
download | colocation-33139b8aea2ee78f5f111679761d16bc821a802c.tar.xz |
add_machine() new
Diffstat (limited to 'html/db.php')
-rw-r--r-- | html/db.php | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/html/db.php b/html/db.php index 503ef13..3e87fcc 100644 --- a/html/db.php +++ b/html/db.php @@ -34,6 +34,38 @@ class MyDB extends SQLite3 { $stm -> close(); return $key_id; } + function add_machine($machine) { + $stm = $this -> prepare('SELECT COUNT(1) FROM machines WHERE machines.name=:name'); + $stm -> bindValue('name', $machine); + $result = $stm -> execute(); + $result = $result -> fetchArray(); + $stm -> close(); + + if ($result[0] == 0) { + $stm = $this -> prepare('INSERT INTO machines (name) VALUES (:machine)'); + $stm -> bindValue('machine', $machine); + $stm -> execute(); + $machine_id = $this -> lastInsertRowID(); + $stm -> close(); + + $stm = $this -> prepare( + 'INSERT INTO "values" (machine_id, state_id) VALUES (:machine, :state)' + ); + $stm -> bindValue('machine', $machine_id); + $result = $this -> query( + 'SELECT states.name, states.id FROM states' + ); + while ($row = $result -> fetchArray()) { + if ($row['name'] == 'running') + $running_id = $row['id']; + $stm -> bindValue('state', $row['id']); + $stm -> execute(); + } + $stm -> close(); + + $this -> add_key_for($machine_id, $running_id, 'self'); + } + } function get_value_id_of($machine, $state) { if (is_int($machine) && is_int($state)) { $stm = $this -> prepare( |