简体   繁体   English

Joomla使用插入到单独的数据库表中

[英]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. 尝试在mysql工作台或phpMyAdmin中测试sql脚本。 Use backticks instead of single quotes around columns 使用反引号代替列周围的单引号

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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