TinyPortal

Development => Resources => Topic started by: rebelrose on June 04, 2007, 05:08:31 PM

Title: Adding database info
Post by: rebelrose on June 04, 2007, 05:08:31 PM
Is it possible to put information from a database that is not on the same site into a block?
Title: Re: Adding database info
Post by: IchBin™ on June 04, 2007, 05:39:40 PM
If you're calling data directly from the database it has to be configure to allow the connection from the place that you're calling it from. MySQL DB's are configured by default to only allow connections from inside the same machine.
Other ways you can do it is to have a cronjob export your data to a file at certain times of the day. Then you can have a script pickup the info in that file and do what you need with it.
Title: Re: Adding database info
Post by: rebelrose on June 04, 2007, 05:40:58 PM
Thank You IchBinâ„¢  :)
Title: Re: Adding database info
Post by: Nikki Sixx on June 04, 2007, 06:18:12 PM
I suppose this scenario would work:

You must be granted a MySQL user account with the privilege "SELECT" (or "ALL") from the SMF database where the block is you want to copy. Your Web server's hostname or IP address must also be permitted to access the MySQL database where that SMF database is housed. You can use this PHP script-

Code: [Select]
<?php

mysql_connect
("your-servers-hostname/IP""your-given-username""your-given-password") or die(mysql_error());

mysql_select_db("their-SMF-database") or die(mysql_error());

$sql 'SELECT * FROM 'smf_tp_blocks' WHERE ( ('smf_tp_blocks' . 'id' = ?? ) ) ';

?>

and where "??" (no surrounding quotes in query) would be the numerical value of the block you wish to copy from their table/database.

In PHPMyAdmin or whatever you like, create a new row in the "smf_tp_blocks" table of your database and enter the same numerical value in the "id" field (both must match). Another PHP script (which I can not write :P) can then import the row's field values you got from the above script which dynamically gathered the block from the other SMF forum you wanted.