1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

how to insert multi row to database ?

Discussion in 'XenForo Development Discussions' started by vinavb, Apr 17, 2012.

  1. vinavb

    vinavb Active Member

    I have line code. I want insert 1 array to db.

    $tests = array(
    '1' => 'asdas',
    '2' => 'asdas',
    '3' => 'asdas',
    '4' => 'asdas',
    $tests as $test){
    $testid $db->insert('******_testcontent', array(
    'testname'    => $test
    $db->insert('******_tests', array(
    'testcontentid'    => $testid,
    'threadid'    => $threadid,
    'dateline'    => XenForo_Application::$time,

    this is code i use model to save. But i want using datawriter save all content .
    How to use dw insert array to db ?

    Thank !!!
  2. simunaqv

    simunaqv Well-Known Member

    This question was previously asked here and answered here.
    vinavb likes this.
  3. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Here is a function from one of my addons which calls on a datawriter to save an array of data:

    	public function saveOptions(array $node)
    		if (!$node['node_id'])
    		$dw = XenForo_DataWriter::create('NodesAsTabs_DataWriter_Options');
    		$existing = $this->getOptionsById($node['node_id']);
    		if (!empty($existing['node_id']))
    The setExistingData() function in the datawriter is used to indicate if you are updating an existing record or not. Then you can use the bulkSet() function to set the array values to be written. The array keys are the names of the database columns.
    vinavb likes this.
  4. vinavb

    vinavb Active Member

    Thank for help. I'm trying this.

Share This Page