"localhost", 'user' => "root", 'pass' => "rossi", 'dbname' => "asteriskcdrdb", 'dbtype' => "mysql", 'cdr_table' => "cdr" ); $dsn = $ini['DB']['dbtype'].'://'.$ini['DB']['user'].':'.$ini['DB']['pass'].'@'.$ini['DB']['host'].':3306/'.$ini['DB']['dbname']; $db =& DB::connect($dsn); if (PEAR::isError($db)) { die($db->getMessage()); } $db->setFetchMode(DB_FETCHMODE_ASSOC); //}}} //open file if(file_exists($filename)) { $fp = fopen($filename,'r'); if(!$fp) { die('Could not open file'); } $ast_tbl = $ini['DB']['cdr_table']; //prepare insert statement $ins_st = $db->prepare("INSERT INTO $ast_tbl (clid,src,dst,dcontext,channel,dstchannel,lastapp,lastdata,calldate,duration,billsec,disposition,amaflags,accountcode,userfield) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); while($row = fgetcsv($fp)) { $clid = $row[0]; if(strpos($clid,'<')!==false) { $clid = '"'.substr($clid,0,-1); } $ins_values = array( $clid, //clid $row[1], //src $row[2], //dst $row[3], //dcontext $row[4], //channel $row[5], //dstchannel $row[6], //lastapp $row[7], //lastdata $row[8], //start -> calldate //$row[9], //answer -> calldate //$row[10], //end -> calldate $row[11], //duration $row[12], //billsec $row[13], //disposition 3, //amaflags : 3 = DOCUMENTATION $row[15], //accountcode //$row[16], //uniqueid $row[17], //userfield ); $db->execute($ins_st,$ins_values); } fclose($fp); } ?>