Forums

SEND FORM DATA TO AN EXTERNAL MYSQL DATABASE

marco4000 11 Dec, 2008
is possible ? thanks
GreyHead 11 Dec, 2008
Hi marco4000,

Yes probably. You'd need to code the connection I think. Or possibly set up a second Joomla DataBase Object.

Bob
marco4000 12 Dec, 2008
Sorry i don't undestand very well, could you explain better?
Max_admin 13 Dec, 2008
Hi Marco,

you need the to write a new mysql connection, do you have any idea with the PHP code needed to open a new connection to the mysql database ?

let me know!

regards
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
GreyHead 14 Dec, 2008
Hi Marco,

From looking at the code I think you can open a new MySQL connection with
<?php
$options = array('host' => 'xxx', 'user' => 'xxx', 'password' => 'xxx', 'database' => 'xxx', 'prefix' = 'xxx', 'select' => 'xxx');
$db2 =& new JDatabaseMySQL($options);
?>
NB Not tested and may not work!

Bob
quantum_leap 01 Aug, 2012
Hi I am sorry I have been trying to connect to an external database on my localhost with no luck. I've followed your example in the tutorial. I've created a test database called names with a all_names table with two fields: id and name. I've entered two records so that I will have some data. My code is:
<input name="name" value="<?php
$options = array(
'host' => 'localhost',
'user' => 'root',
'password' => '',
'database' => 'names',
'prefix' = '',
'select' => true
);
$db =& new JDatabaseMySQL($options);
$query = "
SELECT `name`
FROM `all_names`
WHERE `id` = '1';
";
$db->setQuery($query);
$result = $db->loadResult();
echo $result;

?>" />


It doesn't work. Unfortunately I cannot debug, whenever I set Joomla Debug System to Yes I get a The connection was reset error message.

Is my code correct?
quantum_leap 01 Aug, 2012
Hi your code was wrong. It needed to be
<input name="name" value="<?php

$options = array();
$options['driver'] = 'mysql';        // Database driver name
$options['host'] = 'localhost';      // Database host name
$options['user'] = 'root';       // User for database authentication
$options['password'] = '';   // Password for database authentication
$options['database'] = 'names';   // Database name
$options['prefix'] = '';             // Database prefix
$db = & JDatabase::getInstance($options);
$query = "
SELECT `name`
FROM `all_names`
WHERE `id` = '2';
";
$db->setQuery($query);
$result = $db->loadResult();
echo $result;

?>" />


It works now. Regards...
This topic is locked and no more replies can be posted.