Jeniffer
Jeniffer

Reputation: 97

how to insert data into database at joomla article

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

Upvotes: 2

Views: 3161

Answers (2)

aish
aish

Reputation: 623

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();

Upvotes: 0

Pramod Kumar Sharma
Pramod Kumar Sharma

Reputation: 8012

You can run insert query in joomla in this way.

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

Upvotes: 2

Related Questions