/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#!/usr/bin/env php /** CREATE TABLE `log` ( `id` int(10) unsigned NOT NULL auto_increment, `repo` varchar(255) NOT NULL, `commit` varchar(40) NOT NULL, `date` datetime NOT NULL, `message` text NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `commit` (`commit`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; */ <?php $db = new PDO('mysql:dbname=DB;host=127.0.0.1','USERNAME','PASSWORD'); if ($capture){ // preprocess the log foreach ($capture as $row){ $commits[] = $current; } else { $current[] = $row; } } foreach ($commits as $commit){ $sha = $commit[0]; $v[] = '(?,?,?,?)'; $b[] = $repo; $b[] = $sha; $b[] = $m; $b[] = $d; } $stmt = $db->prepare('insert ignore into log (repo,commit,message,`date`) values' . implode(',',$v)); try { if ($stmt) { if (!$stmt->execute($b)) throw new PDOException;; } else Throw new PDOException; } catch (PDOException $e) { } } ?>
URL: http://jspr.tndy.me/2010/07/store-git-activity-in-mysql-with-php/