Current File : /home/lifechur/carp_evolution_4.1.8/mysql_setup.php
<?php
/*
To set up the database for the mySQL plugin for CaRP Evolution:

1) Create the database in which the data will be stored, or choose an existing
	database, and enter its name in the $database variable below. (Note that
	this script will not create a database for you, but it will create tables
	in an existing database to hold the mySQL plugin's data).
2) Enter the appropriate username, password, and host in the variables below.
	The host setting for most servers is 'localhost'.  It may also be either a
	host name or an IP address, and either may include a port number. A few
	examples: 'localhost', 'localhost:2000', '192.168.1.100:2100',
	'www.theserver.com', 'www.theserver.com:2250'
3) If you want to use different field or table names than are specified by
	default, make any necessary adjustments below and in mysql.php -- I
	recommend only doing this if absolutely necessary to avoid conflicts with
	some other application
4) Upload this script to your webserver
5) Load it in your web browser
6) Verify the the database tables were created
7) Delete this file from your webserver
*/

$database='enter database name here';
$username='enter username here';
$password='enter password here';
$host='localhost';
$feedtable='rssfeeds';
$itemtable='rssitems';
$feedfields=array(
	'feed_id'=>'int primary key auto_increment',
	'url'=>'char(32) not null',	// actually md5(url)
	'real_url'=>'text',
	'last_polled'=>'bigint'
);
$feedindices=array(
	'url'
);
$itemfields=array(
	'item_id'=>'bigint primary key auto_increment',
	'feed_id'=>'int not null',
	'checksum'=>'char(32)',
	'title'=>'varchar(255)',
	'url'=>'varchar(255)',
	'author'=>'varchar(255)',
	'posted'=>'int',
	'updated'=>'int',
	'descr'=>'text',
	'imageurl'=>'varchar(255)',
	'imageheight'=>'smallint',
	'imagewidth'=>'smallint',
	'imagelink'=>'varchar(255)',
	'imagetitle'=>'varchar(255)',
	'guid'=>'varchar(255)',
	'podcasturl'=>'varchar(255)',
	'new'=>'tinyint default "1"'
);
$itemindices=array(
	'feed_id',
	'title'
);
$itemfullindices=array(
	'descr'
);

function InstDBQ($q) {
	global $msconn;
	if (function_exists('mysql_query')) return mysql_query($q);
	else return mysqli_query($msconn,$q);
}
function InstDBE() {
	global $msconn;
	if (function_exists('mysql_query')) return mysql_error($q);
	else return mysqli_error($msconn);
}

if (!($msconn=(($usemysql=function_exists('mysql_query'))
	?mysql_connect($host,$username,$password)
	:mysqli_connect($host,$username,$password,$database))
)) echo 'Error connecting to mySQL ('.InstDBE().')';
else {
	if ($usemysql&&!mysql_select_db($database)) echo 'Error selecting database ('.InstDBE().')';
	else {
		$q='';
		$first=1;
		foreach ($itemfields as $field => $type) {
			$q.=($first?'':',')."$field $type";
			$first=0;
		}
		for ($i=0;$i<count($itemindices);$i++)
			$q.=",index($itemindices[$i])";
		for ($i=0;$i<count($itemfullindices);$i++)
			$q.=",fulltext($itemfullindices[$i])";
		if (!(
			InstDBQ("create table $itemtable ($q);")||InstDBQ("create table $itemtable ($q) ENGINE=MyISAM;")
		)) echo 'Error creating item database ('.InstDBE().')';
		else {
			// some mySQL versions start auto_increment number columns at zero, which we don't want here
			InstDBQ("insert into $itemtable set feed_id=0");
			InstDBQ("delete from $itemtable where feed_id=0");
			$q='';
			$first=1;
			foreach ($feedfields as $field => $type) {
				$q.=($first?'':',')."$field $type";
				$first=0;
			}
			for ($i=0;$i<count($feedindices);$i++)
				$q.=",index($feedindices[$i])";
			if (!InstDBQ("create table $feedtable ($q);")) echo 'Error creating feed database ('.InstDBE().')';
			else {
				InstDBQ("insert into $feedtable set url=\"x\"");
				InstDBQ("delete from $feedtable where url=\"x\"");
				echo 'Your database tables have been created';
			}
		}
	}
} 

return;
?>