General developer forum

My wall post don't work no more. Sniff.

 
Frankie's the name, Moodle's my game!
My wall post don't work no more. Sniff.
Particularly helpful MoodlersPlugin developers

Hi

I have a customised Facebook-like wall which used to work but now doesn't work anymore.  I could post messages in the past, but now no longer.



The screenshot above shows my wall message is posted on the wall. However when I refresh my screen, my post "Hi" disappears.

Below is the warning messages that are displayed if I set my debugging mode to "Developers - extra Moodle debug messages for developers" :-

[start of warnings]
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/goodinstitute/public_html/wall/message_ajax.php:14) in /home/goodinstitute/public_html/lib/classes/session/handler.php on line 42

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/goodinstitute/public_html/wall/includes/db.php on line 15

get_context_instance() is deprecated, please use context_xxxx::instance() instead.
line 3331 of /lib/deprecatedlib.php: call to debugging()
line 24 of /wall/session.php: call to get_context_instance()
line 26 of /wall/message_ajax.php: call to include_once()
[end of warnings]


Here's my code of db.php with line 15 highlighted in bold:

<?php
/* For this to work, this file must be in a child folder of the Moodle folder.

For example, this file should be inside:
/public_html/moodle/wall
where moodle is the parent folder and wall is the child folder.
*/
require "../config.php";
define('DB_SERVER', $CFG->dbhost);
define('DB_USERNAME', $CFG->dbuser);
define('DB_PASSWORD', $CFG->dbpass);
define('DB_DATABASE', $CFG->dbname);
$connection = mysql_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD) or die(mysql_error());
$database = mysql_select_db(DB_DATABASE) or die(mysql_error());
/* TABLES FOR THE CONTENT AND THE RATINGS (MODIFY IF TABLE NAMES ARE
DIFFERENT) */
$content = 'content';
$ratings = 'ratings';
$ip = $_SERVER["REMOTE_ADDR"]; //IP ADDRESS
?>

I have some questions.


Question1:  How do I solve the "Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/goodinstitute/public_html/wall/message_ajax.php:14) in /home/goodinstitute/public_html/lib/classes/session/handler.php on line 42" ?

Question2: with regards to my usage of mysql_connect() what am I doing wrong?

Question3: what is get_context_instance() is deprecated, please use context_xxxx::instance() instead. ?

Thanks anyone who can help me out. "Need a little help here" (Neo, The Matrix)
Regards
Frankie Kam

 
Average of ratings: -
Davo
Re: My wall post don't work no more. Sniff.
Core developersParticularly helpful MoodlersPlugin developers

Since Moodle 2.2, any calls to get_context_instance() should be replaced with one of:

  • context_system::instance()
  • context_coursecat::instance($catid)
  • context_course::instance($courseid)
  • context_module::instance($cmid)
  • context_block::instance($blockid)
  • context_user::instance($userid)

It should be fairly easy to work out which.

In terms of DB access, you should never have used mysql_* functions in the first place - you should always use the Moodle DB functions: https://docs.moodle.org/dev/Data_manipulation_API

The 'session' error may well go away once the other warnings have been fixed (as it is saying it can't start the new session as there has already been some content output - the content that has been output is the other warning messages).


 
Average of ratings: Useful (1)