简体   繁体   中英

Joomla using insert into a separate database table

$option = array();
$option['driver'] = 'mysql'; // Database driver name
$option['host'] = 'localhost'; // Database host name
$option['user'] = '*****'; // User for database authentication
$option['password'] = '********'; // Password for database authentication
$option['database'] = 'teste_dados'; // Database name
$db = JDatabase::getInstance( $option ); 

// Create a new query object.

$query = $db->getQuery(true);

/* // Insert columns.

$columns = array('id_teste','testes','time');

// Insert values.

$values = array(4,'loucura3',date("h:i:s"));

// Prepare the insert query.

$query->insert($db->quoteName('teste1'));
$query->columns($db->quoteName($columns));
$query->values(implode(',', $values));

or

$query="INSERT INTO teste1('id_teste','testes','time') VALUES (4,'loucura3','".date("h:i:s")."')";

// Set the query using our newly populated query object and execute it.

$db->setQuery($query);
$db->execute();

Both options gives the following error message:

An error has occurred while processing your request.

You may not be able to visit this page because of:

an out-of-date bookmark/favourite
a mistyped address
a search engine that has an out-of-date listing for this site
you have no access to this page

Go to the Home Page

Home Page

If difficulties persist, please contact the System Administrator of this site and report the error below.

 0 SQL=INSERT INTO teste1('id_teste','testes','time') VALUES (4,'loucura3','05:11:00') 

I`ve seen some similar problems and their fixes and none of them workd for me any ideas?.

Try testing the sql script in mysql workbench or phpMyAdmin. Use backticks instead of single quotes around columns

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM