scratch – Diff between revs 125 and 126
?pathlinks?
Rev 125 | Rev 126 | |||
---|---|---|---|---|
Line 94... | Line 94... | |||
94 | ) |
94 | ) |
|
95 | ); |
95 | ); |
|
Line 96... | Line 96... | |||
96 | |
96 | |
|
97 | ## If we have any tags then insert them into the database. |
97 | ## If we have any tags then insert them into the database. |
|
- | 98 | if(!empty($tags)) { |
||
- | 99 | ## Connect or create the scratch database. |
||
- | 100 | $db = new PDO('sqlite:db/scratch.sqlite3'); |
||
- | 101 | ## Set the error mode to exceptions. |
||
98 | if(!empty($tags)) { |
102 | $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|
99 | try { |
- | ||
100 | ## Connect or create the scratch database. |
- | ||
101 | $db = new PDO('sqlite:db/scratch.sqlite3'); |
- | ||
102 | ## Set the error mode to exceptions. |
- | ||
103 | $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
103 | try { |
|
104 | |
- | ||
105 | ## Begin the transaction |
104 | |
|
106 | $db->beginTransaction(); |
105 | $db->beginTransaction(); |
|
107 | |
106 | |
|
108 | ## Create the tags table if it does not exist. |
107 | ## Create tags table if it does not exist. |
|
109 | $db->query('CREATE TABLE IF NOT EXISTS "tags" ("hash" text NOT NULL COLLATE NOCASE, "tag" text COLLATE NOCASE)'); |
108 | $db->query('CREATE TABLE IF NOT EXISTS "tags" ("hash" text NOT NULL COLLATE NOCASE, "tag" text COLLATE NOCASE)'); |
|
110 | |
109 | |
|
111 | ## Insert all the tags for the file. |
110 | ## Now add all the tags. |
|
112 | foreach($tags as $tag) { |
111 | foreach($tags as $tag) { |
|
113 | $q = $db->prepare("INSERT INTO tags(hash, tag) VALUES(:hash, :tag)"); |
- | ||
114 | $q->execute( |
- | ||
115 | array( |
112 | $q = $db->prepare('REPLACE INTO "tags" ("hash", "tag") VALUES(:hash, :tag)'); |
|
116 | ':hash' => $file, |
113 | $q->bindParam(':hash', $file); |
|
117 | ':name' => $tag |
- | ||
118 | ) |
114 | $q->bindParam(':tag', $tag); |
|
119 | ); |
115 | $q->execute(); |
|
120 | } |
- | ||
121 | |
- | ||
122 | ## Commit the transaction. |
116 | } |
|
123 | $db->commit(); |
117 | $db->commit(); |
|
- | 118 | } catch (Exception $e) { |
||
124 | } catch (Exception $e) { |
119 | error_log($e); |
|
125 | ## Rollback. |
120 | ## Rollback. |
|
126 | $db->rollback(); |
121 | $db->rollback(); |
|
127 | } |
122 | } |
|
128 | } |
123 | } |