We build. You grow.

Get best community software here

Start a social network, a fan-site, an education project with oxwall - free opensource community software

SQL query | Forum

S. Bourdon
S. Bourdon Sep 2 '13
Hello,


When a specific function is called within the Questions / Polls plugin, I would like to execute an SQL query.


The function is the following:


    public function addOption( $questionId, $userId, $text, $time = null )

    {

        $option = new QUESTIONS_BOL_Option();

        $option->questionId = (int) $questionId;

        $option->text = $text;

        $option->userId = (int) $userId;

        $option->timeStamp = empty($time) ? time() : $time;


        $this->optionDao->save($option);


        OW::getEventManager()->trigger( new OW_Event(self::EVENT_OPTION_ADDED, array(

            'questionId' => $questionId,

            'text' => $text,

            'userId' => $userId,

            'id' => $option->id

        )));


        return $option;

    }



What I would like is to execute the following query:


$query = 'UPDATE `ow_questions_activity` SET `timeStamp` = time() WHERE `activityId` = ' . $questionId;

$result = mysql_query($query) or die ("Cannot execute query: $query");        


I've tried to add this query after the function but it never works...

Why can't I simply add this query to the current function?

How should I proceed to execute this query whenever this function is called?


Thank you very much for your help and support!

The Forum post is edited by S. Bourdon Sep 2 '13
S. Bourdon
S. Bourdon Sep 2 '13
Got it (thanks to the crash course)!


$actual_time = time();

$sql = "UPDATE `" . OW_DB_PREFIX . "questions_activity` SET `timeStamp` = " . $actual_time . " WHERE `activityId` = " . $questionId;

OW::getDbo()->query($sql);

The Forum post is edited by S. Bourdon Sep 3 '13