[IRCServices Coding] XML Export to mySQL with PHP

Dereck Martin dmartin at tekconxus.com
Sun Aug 5 01:14:11 PDT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello All,

I have wrote a php script that will essentially sync up the services xml
export found in the /dbaccess/xml-export/ of http server to mysql.  It
doesn't do all the values, but most of the them (at least the ones most
care about).  I will run this as a night cron job.

This script basically takes the most current xml export, parses it, and
then compares it to the mysql database.  If there are new or modified
entries it will add or update them.  If there are any entries that are
old and need to be removed (expired nicks/channels/unlinked nicks), it
deletes them.

I am sharing this script in hopes someone else may find it useful.  The
are two scripts.  One script creates the tables in mysql.  The second
script does all the other work.

The script is designed to only be ran once a day.  I am using DATE
stamps to distinguish between out of date entries and new ones.
Multiple runs in the same day will only update or add new entries.
Expired entries will only be removed the following day.

You can find my script here:
  http://www.tekconxus.com/files/ircservices-xml2mysql-0.5.tag.gz

Setup Instructions:

1. You will need to perform this command in mysql:

	CREATE DATABASE ircservices;

2. Modify the create_tables.php database variables.
3  Run "php -f create_tables.php" (only needs to be done once)
4. Modify the ircservices-xml2mysql.php database & xml variables.
5. Run "php -f ircservices-xml2mysql.php"

It will do its magic and even display some little progress graphics.
	(+) Add, (-) Delete, (^) Update

If there is enough curiosity in this script, I will add all entries from
the XML file.  For those interested in the output...during this run one
nick was added and one deleted.  The rest of the entries were synced.

###########################################################
fatbastard scripts # php -f ircservices-xml2mysql.php
- --04:10:49--  http://10.10.0.4:8080/dbaccess/xml-export/
           => `ircservices.xml'
Connecting to 10.10.0.4:8080... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/plain]

    [ <=>
                                        ] 11,225        --.--K/s

04:10:49 (13.59 MB/s) - `ircservices.xml' saved [11225]

Processing NickInfo Section:
^^+^-
Processing ChannelInfo Section:
^^^^
Processing NickGroupInfo Section:
^^^^
Updated: 11
Added: 1
Deleted: 1

###########################################################
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGtYbTZgcWLP4PXgERAouDAJ4/g8VQMCO1vgEX5Yd4SZtAJLgsPQCgnwdm
BXbK3a2j5efoIMru76pxkKA=
=pxA1
-----END PGP SIGNATURE-----
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ircservices-xml2mysql-0.5.tar.gz
Type: application/gzip
Size: 2814 bytes
Desc: not available
Url : ../attachments/20070805/bc355b84/ircservices-xml2mysql-0.5.tar.bin