Documentation You are here: start » integration » mysql
type:
integration
system:
MySQL
name:
XML Backup
description:
Store/backup your raw XML datafeeds in a MySQL database. Useful to back them up for future use.
tag:
xml, mysql, backup, testing

Raw XML -> MySQL

Please note: The code on this page is submitted by members of the FoxyCart community, and may not verified by FoxyCart.com LLC in any way, shape, or form. Please double check the code before installing. If you need help with it please post in our forum, but if we cannot offer assistance (due to unfamiliarity with this particular system or language) we apologize in advance.

Description

This can be handy for a variety of uses. Once you have your order information locally, the possibilities are endless.

This is for advanced users. The code below just dumps the XML into a MySQL table, not much more. You could use this as a starting point, but you'll need to know what you're doing to make it do anything.

<wrap tip>Before you get started with this… make sure you wouldn't be better served by using the API or the instant datafeeds.

<?
# schema:
# CREATE TABLE CREATE TABLE `foxy_orders` (
# `id` int(11) NOT NULL auto_increment,
# `order_id` int(11) default NULL,
# `foxy_data` text NOT NULL,
# `created_at` datetime NOT NULL default '0000-00-00 00:00:00',
# `processed_at` datetime default NULL,
# PRIMARY KEY (`id`)
# ) ENGINE=MyISAM AUTO_INCREMENT=227 DEFAULT CHARSET=utf8
//
// Finally, set your key to decrypt the XML that you receive from FoxyCart.
// This must match *exactly* what you entered at http://www.foxycart.com/admin
$key = "abracadabra";
 
if (isset($_POST["FoxyData"])) {
	// ===================================================================================================
	// DECRYPT YOUR DATA
	// (do not modify)
	// ===================================================================================================
	// Decrypt the data using your $key
	// First, include the rc4crypt.php file
	// include 'class.rc4crypt.php';
	// This file has been included in this code, below.
 
	// Then decrypt the XML
	$FoxyData_encrypted = urldecode($_POST["FoxyData"]);
	$FoxyData_decrypted = rc4crypt::decrypt($key,$FoxyData_encrypted);
 
	// ===================================================================================================
        // Replace DBHOST, DBUSER, DPASS, DATABASE as needed for your environment.
 
	if (!mysql_connect('DBHOST', 'DBUSER', 'DBPASS')) die("no connection to MySQL");
	if (!mysql_select_db('DATABASE')) die("couldn't select database");
 
	mysql_query("INSERT INTO foxy_orders (created_at,foxy_data) VALUES (NOW(),'".mysql_escape_string($FoxyData_decrypted) ."')");
 
	echo "foxy";
} else {
	echo "no post data!";
}
 
/* vim: set expandtab shiftwidth=4 softtabstop=4 tabstop=4: */
 
/**
 * RC4Crypt 3.2
 *
 * RC4Crypt is a petite library that allows you to use RC4
 * encryption easily in PHP. It's OO and can produce outputs
 * in binary and hex.
 *
 * (C) Copyright 2006 Mukul Sabharwal [http://mjsabby.com]
 *     All Rights Reserved
 *
 * @link http://rc4crypt.devhome.org
 * @author Mukul Sabharwal <mjsabby@gmail.com>
 * @version $Id: class.rc4crypt.php,v 3.2 2006/03/10 05:47:24 mukul Exp $
 * @copyright Copyright &copy; 2006 Mukul Sabharwal
 * @license http://www.gnu.org/copyleft/gpl.html
 * @package RC4Crypt
 */
 
/**
 * RC4 Class
 * @package RC4Crypt
 */
class rc4crypt {
	/**
	 * The symmetric encryption function
	 *
	 * @param string $pwd Key to encrypt with (can be binary of hex)
	 * @param string $data Content to be encrypted
	 * @param bool $ispwdHex Key passed is in hexadecimal or not
	 * @access public
	 * @return string
	 */
	function encrypt ($pwd, $data, $ispwdHex = 0)
	{
		if ($ispwdHex)
			$pwd = @pack('H*', $pwd); // valid input, please!
 
		$key[] = '';
		$box[] = '';
		$cipher = '';
 
		$pwd_length = strlen($pwd);
		$data_length = strlen($data);
 
		for ($i = 0; $i < 256; $i++)
		{
			$key[$i] = ord($pwd[$i % $pwd_length]);
			$box[$i] = $i;
		}
		for ($j = $i = 0; $i < 256; $i++)
		{
			$j = ($j + $box[$i] + $key[$i]) % 256;
			$tmp = $box[$i];
			$box[$i] = $box[$j];
			$box[$j] = $tmp;
		}
		for ($a = $j = $i = 0; $i < $data_length; $i++)
		{
			$a = ($a + 1) % 256;
			$j = ($j + $box[$a]) % 256;
			$tmp = $box[$a];
			$box[$a] = $box[$j];
			$box[$j] = $tmp;
			$k = $box[(($box[$a] + $box[$j]) % 256)];
			$cipher .= chr(ord($data[$i]) ^ $k);
		}
		return $cipher;
	}
	/**
	 * Decryption, recall encryption
	 *
	 * @param string $pwd Key to decrypt with (can be binary of hex)
	 * @param string $data Content to be decrypted
	 * @param bool $ispwdHex Key passed is in hexadecimal or not
	 * @access public
	 * @return string
	 */
	function decrypt ($pwd, $data, $ispwdHex = 0)
	{
		return rc4crypt::encrypt($pwd, $data, $ispwdHex);
	}
}
 
?>

Site Tools