LMSouq
moodle-core Open

moodle_database::insert_record_raw() no fields found

US
user3178356
1 month ago
3 views
Problem Description
I'm trying to extract some data from an URL and store it into a table I created in Moodle, and it shows the error in Title. My goal is to extract all the values inside the attribute "nome" on cursos>curso and put them on my table ecoclipaluno. Example Link. parameters of build URL, when changed, can give more values to store. Or less. https://clip.unl.pt/sprs?lg=pt&year=2013&uo=97747&srv=rsu&p=1&tp=s&md=3&rs=8145&it=5&it=1030123459 function buildURL($year, $period, $typeperiod,$course) { return 'https://clip.unl.pt/sprs?lg=pt&year='.$year.'&uo=97747&srv=rsu&p='.$period.'&tp='.$typeperiod.'&md=3&rs='.$course.'&it=5&it=1030123459'; } function doRequest_with_FileGetContents($url) { return file_get_contents($url); } function processXMLforCourse($xmlContent){ $xmlObj= new SimpleXMLElement($xmlContent); $result=array(); foreach($xmlObj->unidade_curricular->cursos->curso as $curso){ $result[]= $curso->attributes()->nome; } return $result; } $context=get_context_instance(CONTEXT_COURSE,$courseid); //$shortname=$course->shortname; $idnumber=$course->idnumber; $timecreated=$course->startdate; $typeperiod='s'; if(date("m",$timecreated) >07 && date("m",$timecreated) <13){ $period='1'; $url=buildURL(date("Y",strtotime('+1 year',$timecreated)),$period,$typeperiod,$idnumber); // 1st semester } else{ $period='2'; $url=buildURL(date("Y",$timecreated),$period,$typeperiod,$idnumber); // 2nd semester } $content_b=doRequest_with_FileGetContents($url); $dataClipCourse= processXMLforCourse($content_b); $DB->insert_record('ecoclipaluno',$dataClipCourse); From the Moodle API of data manipulation, the method insert_record has 4 parameters, the last 2 being optional, but none of them specifies the field. I wanted to insert $dataClipCourse to the field coursename. How can I pull that off? ![enter image description here][1] array(8) { [0]=> object(SimpleXMLElement)#37 (1) { [0]=> string(54) "Licenciatura em Engenharia Informática (Tronco comum)" } [1]=> object(SimpleXMLElement)#36 (1) { [0]=> string(38) "Mestrado em Matemática e Aplicações" } [2]=> object(SimpleXMLElement)#44 (1) { [0]=> string(92) "Mestrado em Matemática e Aplicações, Especialização em Álgebra, Lógica e Computação" } [3]=> object(SimpleXMLElement)#45 (1) { [0]=> string(82) "Mestrado em Matemática e Aplicações, Especialização em Matemática Financeira" } [4]=> object(SimpleXMLElement)#46 (1) { [0]=> string(104) "Me...

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base