UBB.Dev
Posted By: Tusk Custom Islands - 07/08/2021 8:07 AM
Hi,
Is there any way of doing db update, delete and insert in a custom Islands?
Posted By: Gizmo Re: Custom Islands - 07/08/2021 6:14 PM
You can execute database queries in Custom Islands by following the syntax we utilize in the software (examples in the scripts you'll likely find helpful); an example would be the Random Image island at UBBCentral (this code is posted on that forum as well):
Code
/* PHP CODE HERE */
$query = "
	SELECT POST_ID, FILE_DIR, FILE_NAME
	FROM {$config['TABLE_PREFIX']}FILES
	WHERE (FILE_DIR <> '' AND FILE_DIR IS NOT NULL)
	  AND (FILE_TYPE = 'jpg'
	   OR FILE_TYPE = 'gif'
	   OR FILE_TYPE = 'jpg'
	   OR FILE_TYPE = 'jpeg'
	   OR FILE_TYPE = 'png')
	ORDER BY rand()
	LIMIT 1
";
$sth = $dbh->do_query($query, __LINE__, __FILE__);
list($postId, $fDir, $fName) = $dbh->fetch_array($sth);

/* BODY HERE */
$body = <<<EOF

<div class="acvt">
<div style="height:{$config['MAX_THUMB_W_H']}px;overflow:hidden;position:relative;width:100%;display:inline-block;">
<a href="{$config['BASE_URL']}/ubbthreads.php?ubb=showgallery&Number=$postId"><img src="{$config['BASE_URL']}/gallery/$fDir/medium/$fName" alt="" title="" class="p2 cp oi" style="position:absolute;left:-100%;right:-100%;top:-100%;bottom:-100%;margin:auto;max-width:280px;min-height:100%;"></a>
</div>
</div>

EOF;

Please be sure that your islands are set to cache their output to a reasonable value as short timings may result in strain on your database server depending on traffic trends.
Posted By: Tusk Re: Custom Islands - 07/09/2021 8:08 AM
HI,
We have two island that require a database updates, one is a game recruitment list with an two options to add or remove items from drop down lists, this requires and insert and delete. We also have an island that the users can generate dice rolls and the result is posted in the forum there in (so no cheating), this one generate a post and saves it. We have a few islands that just have lists of data like your random images, but we need to have the option to Update, Insert and Delete records, which do not appear work in an island.
Currently these two islands are written in Perl and work fine, I've been tasked with converting all of our Perl scripts to PHP as more and more ISP no-longer support Perl.
Posted By: Gizmo Re: Custom Islands - 07/09/2021 11:42 PM
I generally only do SQL queries to pull data and use forms to post to other scripts which do processing.
© UBB.Developers