Jump to content


- - - - -

Mysql php help


  • Please log in to reply
2 replies to this topic

#1 Subliminal1

Subliminal1

    Member

  • Members
  • PipPipPip
  • 35 posts
  • IPB Version:v3.0.x

Posted 24 December 2009 - 10:43 PM

Hey there :)

I was wondering if you could help me with a little php/mysql knowledge. I am only given these instructions for installing this:

To install it run the contents of database.sql as a mysql query in some database. Then create a file named connect.php that connects to mysql and selects the right table.

I am done installing the database.sql... Now I just need to make a php script that connects to the mysql database and selects the table "serverinfo"... I am not very good with php, and was hoping you guys could maybe help me a bit, I've looked through google tutorials but haven\'t found much help ;)

Thanks in advance!

Edited by Subliminal1, 24 December 2009 - 10:43 PM.


#2 Sandi

Sandi

    Coder

  • IM Supporters
  • PipPipPipPipPipPipPip
  • 812 posts
  • Location:Janesville, Wisconsin
  • Real Name:Sandra
  • IPB Version:v3.2.x
Contributor

Posted 25 December 2009 - 09:28 PM

How about a script I made to export a single member group as an example? (Ya it is down and dirty but works) ;)

Substitute what you need for your DB and table(s) in the appropriate places. Disregard the file write and xml stuff.

<?php
	$host = 'localhost';
	$user = 'Sandi';
	$pass = '********';
	$database = 'b16';
	 
	 $member_data = array();
	$my_connect = mysql_connect($host, $user, $pass);

	if (!$my_connect) {
		die('Could not connect: ' . mysql_error());
	}
	mysql_select_db($database, $my_connect) or die("Could not find database."); 

	$query  = "SELECT * FROM ibf_members WHERE mgroup = 7";
	$member_group = mysql_query($query, $my_connect) or die("Data not found.");
	$num_rows = mysql_num_rows($member_group);
	if (!$num_rows) die("Could not find any members.");
	while( $row = mysql_fetch_assoc($member_group) )
	{
		$member_data[] = $row;
	}
	
	$fh = fopen("group.xml", "w+");
	if($fh==false) die("Unable to create group.xml file");
	
	foreach($member_data as $r)
	{
		$member_data = explode(',',$r);
		$xml_output .= "id_counter, "; // counter set on import
		$xml_output .= "'" . $r['name'] . "', ";
		$xml_output .= "mgroup, "; // mgroup replaced on import'
		$xml_output .= "'" . $r['email'] . "', ";
		$xml_output .= $r['joined'] . ", ";
		$xml_output .= "'" . $r['ip_address'] . "', ";
		// Remaining ibf_member columns deleted for example brevity.
		$xml_output .= "\n";
		echo $r['members_display_name'] . "<br />";
		fwrite($fh, $xml_output);
		$xml_output = '';
	}
	fclose($fh);
	mysql_close($my_connect);
	echo "members exported successfully";
?>

Posted Image


#3 Subliminal1

Subliminal1

    Member

  • Members
  • PipPipPip
  • 35 posts
  • IPB Version:v3.0.x

Posted 26 December 2009 - 05:55 AM

Thanks!  I'll give this a try!




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users