cybertick Posted November 14, 2011 Share Posted November 14, 2011 I am trying to insert the current Date/Time into mysql database using the following code. I do not understand how $submitDate & $submitTime are to be set. Will this work as coded? <?php class SubmitDateRecord { const DB_TABLE = 'timesheet'; const DB_FIELD_SUBMIT_TIME = 'submit_time'; private $submitDate; private $submitTime; public function setSubmitDate($submitDate) { $this->submitDate = $submitDate; } public function getSubmitDate() { return $this->submitDate; } public function setSubmitTime($submitTime) { $this->submitTime = $submitTime; } public function getSubmitTime() { return $this->submitTime; } public function addRecord() { $insertTable = "`".self::DB_TABLE."`"; $insertFields[] = "`".self::DB_FIELD_SUBMIT_TIME."`"; $insertValues[] = "'{$this->submitDate} {$this->submitTime}'"; $sqlBuilder = new SQLQBuilder(); $query = $sqlBuilder->simpleInsert($insertTable, $insertValues, $insertFields); $dbConnection = new DMLFunctions(); $result = $dbConnection->executeQuery($query); if ($result) { return true; } else { return false; } } private function _buildRecordObjects($result) { while ($row = mysql_fetch_array($result)) { $submitdateObj = new SubmitDateRecord(); $submitdateObj->setAttendanceId($row['attendance_id']); $submitdateObj->setEmployeeId($row['employee_id']); /* $row['submit_time'] comes in '0000-00-00 00:00:00' format. * We want date in '0000-00-00' format and time in '00:00' format. */ $tmpArr = explode(' ', $row['submit_time']); $submitdateObj->setSubmitDate($tmpArr[0]); $submitdateObj->setSubmitTime(substr($tmpArr[1], 0, 5)); // Omiting 'seconds' part is ok since it is always zero $submitdateObj->setStatus($row['status']); $submitdateArr[] = $submitdateObj; } return $submitdateArr; } } Quote Link to comment https://forums.phpfreaks.com/topic/251095-new-to-oop-when-does-a-method-get-set/ Share on other sites More sharing options...
Stooney Posted November 14, 2011 Share Posted November 14, 2011 <?php $sdr=new SubmitDateRecord(); $sdr->setSubmitDate('the date'); $sdr->setSubmitTime('the time'); $sdr->addRecord(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/251095-new-to-oop-when-does-a-method-get-set/#findComment-1287933 Share on other sites More sharing options...
cybertick Posted November 15, 2011 Author Share Posted November 15, 2011 Thanks Quote Link to comment https://forums.phpfreaks.com/topic/251095-new-to-oop-when-does-a-method-get-set/#findComment-1288232 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.