mysql - Cannot modify an external database in Joomla! 3.0.3. using php request -
i have been creating website on local server joomla! 3.0.3. have connected external database website , can query (see previous question of mine: where statement not working in joomla! 3.0.3. php request). when try modify entry in external database, server returns error screen.
here's code i'm using in end of joomla! (using sourcerer extension). try add new currency mysql "currency" table in external database.
<?php /**///////// load external database (i.e. not joomla one) /////////**/ $option = array(); $option['driver'] = 'mysql'; // database driver name $option['host'] = 'localhost'; // database host name $option['user'] = 'root'; // user database authentication $option['password'] = ''; // password database authentication $option['database'] = 'externaldatabase'; // database name $db = jdatabase::getinstance( $option ); /**///////// create new query object /////////**/ $query = $db->getquery(true); //ok /**///////// select records & insert new row /////////**/ $columns=array('id', 'currencycode', 'fullname'); $values=array('3', 'gbp', 'pound sterling'); $query->insert($db->quotename('currency')); $query->columns($db->quotename($columns)); $query->values(implode(',', $values); /**///////// reset query /////////**/ $db->setquery($query); //ok try { $result = $db->execute(); } catch (exception $e) { // catch } ?>
the browser returns following 2 errors:
- parse error: syntax error, unexpected ';' in c:\wamp\www\plugins\system\sourcerer\helper.php(450) : runtime-created function on line 46
- fatal error: function name must string in c:\wamp\www\plugins\system\sourcerer\helper.php on line 454
do have suggestion? in advance help.
here's updated code that's working of interested!
<?php $values=array('3', '"gbp"', '"pound sterling"'); $query->insert($db->quotename('currency')); $query->columns($db->quotename($columns)); $query->values(implode(',', $values)**)**; ?>
you forgot closing parenthesis:
$query->values(implode(',', $values); // here ----^
so must be: $query->values(implode(',', $values));
Comments
Post a Comment