how to insert data into database at joomla article

为君一笑 提交于 2019-12-11 03:41:21

问题


I am beginner in joomla development. I know PHP, MySql. But I want to insert data into database (phpmyadmin) in joomla. how to do it in a joomla article. Thanks


回答1:


You can run insert query in joomla in this way.

    $db =& JFactory::getDBO();
    $query = "INSERT INTO '#__example_table' ('name','email','username')
            VALUES ('John Smith','johnsmith@domain.example','johnsmith')";
    $db->setQuery($query);
    $db->query();



回答2:


Another way of insert query.

$db = JFactory::getDBO();

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

Get column names to a variable as array.

$columns = array('fieldname1','fieldname2');
$values = array(1,$db->quote('my value'),$db->quote('my message');

Insert query

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

Set the query

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


来源:https://stackoverflow.com/questions/10757084/how-to-insert-data-into-database-at-joomla-article

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!