]> Tony Duckles's Git Repositories (git.nynim.org) - delicious-utils.git/blob - delicious-dump/php-delicious/examples/mysql-backup/restore-from-mysql.php
Initial commit
[delicious-utils.git] / delicious-dump / php-delicious / examples / mysql-backup / restore-from-mysql.php
1 <?php
2 // Import into del.icio.us from MySql
3 // Written by Ed Eliot (www.ejeliot.com) - November 2006
4
5 require('../../php-delicious.inc.php'); // see www.ejeliot.com/pages/php-delicious for more details on library
6
7 define('DELICIOUS_USER', 'YOUR_USER');
8 define('DELICIOUS_PASS', 'YOUR_PASS');
9
10 define('MYSQL_SERVER', 'YOUR_HOST');
11 define('MYSQL_DB', 'delicious');
12 define('MYSQL_USER', 'YOUR_USER');
13 define('MYSQL_PASS', 'YOUR_PASS');
14
15 define('POSTS_TABLE', 'posts');
16 define('TAGS_TABLE', 'tags');
17
18 $oDelicious = new PhpDelicious(DELICIOUS_USER, DELICIOUS_PASS);
19
20 if ($oDb = mysql_connect(MYSQL_SERVER, MYSQL_USER, MYSQL_PASS)) {
21 if (mysql_select_db(MYSQL_DB, $oDb)) {
22 if ($oPosts = mysql_query("select url, description, notes, hash, updated from posts order by updated asc", $oDb)) {
23 while ($aPost = mysql_fetch_assoc($oPosts)) {
24 $aTags = array();
25 if ($oTags = mysql_query(sprintf("select tag from tags where hash = '%s' order by tag asc", $aPost['hash']))) {
26 while ($aTag = mysql_fetch_assoc($oTags)) {
27 $aTags[] = $aTag['tag'];
28 }
29 }
30 $oDelicious->AddPost($aPost['url'], $aPost['description'], $aPost['notes'], $aTags, $aPost['updated'], true);
31 }
32 }
33 } else {
34 echo mysql_error($oDb);
35 }
36 mysql_close($oDb);
37 } else {
38 echo "Could not connect to MySql server.";
39 }
40 ?>