<?php

class Crash {

	public function create($db, $member_id, $ip, $callstack, $data, $notes) {
		syslog(LOG_WARNING,"Crash::create(\$db, $member_id, $ip, \$callstack, \$data, \$notes)");
		$db_member_id = (int)$member_id;
		$db_ip = pg_escape_string($ip);
		$db_callstack = pg_escape_string($callstack);
		$db_data = pg_escape_string($data);
		$db_notes = pg_escape_string($notes);
		$db_number = md5(time());

		$q = "INSERT INTO crash_log (member_id, ip, callstack, data, notes, number) ";
		$q.= " VALUES(${db_member_id}, '${db_ip}', '${db_callstack}', '${db_data}', '${db_notes}','${db_number}') RETURNING id,number";
		//syslog(LOG_WARNING,$q);
		$r = pg_query($db, $q);
		if ($r && pg_num_rows($r) && $f=pg_fetch_assoc($r)) {
			return $f;
		}
		return NULL;
	}
}

// vi:ts=2

