Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

How to: Extracting email addresses from your vanilla database.

edited February 2007 in Vanilla 1.0 Help
This is, "for me", a simple way to extract email addresses. Great if you'd like to send out a newsletter to your members. This script is not intended to be placed anywhere within the vanilla installation folder/directory.

Im no PHP expert so there may me a more efficient way to access the database and display the results but this is a function I compiled to handle all of my query's.

I have this in my header file, which is not located anywhere within the vanilla installation:
<?php # my function for handling query's function funcSql($table,$type,$query){ mysql_pconnect(localhost,"USER","PASSWORD"); @mysql_select_db($table) or die("Unable to select database"); if($type=="SELECT"){ global $result; global $num; $result=mysql_query($query); $num=mysql_num_rows($result); }elseif($type=="INSERT" || $type=="UPDATE" || $type=="DELETE"){ $result=mysql_query($query); } } # handy little function to print out the array. function printr($array_string){ echo '<pre>'; print_r($array_string); echo '</pre>'; } ?>

Now this will output all of the email addresses into an array, you can easily work from there.

<?php funcSql("TABLE_NAME","SELECT","SELECT * FROM LUM_User"); //LUM_User should be the correct table to extract from. for($i=0;$i<$num;$i++){ $emails[] = mysql_result($result,$i,"Email"); } printr($emails); ?>

Hope this helps some people. Once I finish the newsletter script "that all of the above was intended for" I will update this "Discussion", shouldn't be longer than a day or two. -- If you need need help understanding my jibberish, or have a way I can improve the code above please share! =]

Comments

  • edited February 2007
    edit
  • NickENickE New
    edited February 2007
    selecting the entire row when you only need one column isn't a very efficient method of going about it. you're also sort of reinventing the wheel with all those mysql wrappers. it'd be simpler to do something along these lines (apologies if it's buggy, not in the position to test things at the moment):
    function RetrieveEmails()
    {
    	global $Context;
    	
    	$s = $Context->ObjectFactory->NewContextObject($Context, 'SqlBuilder');
    	$s->SetMainTable('User');
    	$s->AddSelect('Email');
    	
    	$data = $Context->Database->Select($s, 'Extension', 'RetrieveEmails', 'An error occurred while attempting to retrieve users\' email.');
    	while($row = $Context->Database->GetRow($data))
    	{
    		if(!isset($row['Email'])) continue;
    		
    		echo $row['Email'];
    	}
    }
  • edited February 2007
    Is there some type of class to go a long with that? Or is that "Vanilla Talk"?
  • it's meant to be executed in the vanilla environment, if that's what you mean (ie. vanilla has to be initialized). there isn't really a way you can avoid initializing vanilla to some extent, really, as you need the database, column and table names.
  • "Vanilla Talk" = coding within the vanilla environment. Yes

    How-ever the example I made was not intended to be used within the vanilla environment, you can use it anywhere on your localhost not inside the vanilla install path.
  • well you can use that outside of the vanilla dir as well, just as long as you've included the right files (some of which you'll have to include anyways to get the names for everything).
  • Right, again my example is more like an external extension.
This discussion has been closed.