Inserting a Record

Joomla 3.3 hakkında genel bilgiler
Cevapla
abdulkadirlevent
Site Admin
Mesajlar: 24
Kayıt: Pzr Oca 19, 2020 4:27 pm

Inserting a Record

Mesaj gönderen abdulkadirlevent »

Inserting a Record

Kod: Tümünü seç

// Get a db connection.
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);
// Insert columns.
$columns = array('user_id', 'profile_key', 'profile_value', 'ordering');
// Insert values.
$values = array(1001, $db->quote('custom.message'), $db->quote('Inserting a record using insert()'), 1);
// Prepare the insert query.
$query
    ->insert($db->quoteName('#__user_profiles'))
    ->columns($db->quoteName($columns))
    ->values(implode(',', $values));
// Set the query using our newly populated query object and execute it.
$db->setQuery($query);
$db->execute();

Using an Object
// Create and populate an object.

Kod: Tümünü seç

$profile = new stdClass();
$profile->user_id = 1001;
$profile->profile_key='custom.message';
$profile->profile_value='Inserting a record using insertObject()';
$profile->ordering=1;

// Insert the object into the user profile table.
$result = JFactory::getDbo()->insertObject('#__user_profiles', $profile);

Cevapla