コード例 #1
0
	public function getUserLanguage( $username ) {
		global $mysql_info;
		DBTools::connect( $mysql_info );

		$username = mysql_real_escape_string( $username );
		$row = DBTools::doQuery( "SELECT uiLanguage from auth where username=\"$username\"" );
		return $row["uiLanguage"];
	}
コード例 #2
0
function saveExercise( $exercise, $userName = null ) {
	global $mysql_info;
	DBTools::connect( $mysql_info );
	$id = mysql_real_escape_string( $exercise->getId() );
	# if (id==0) throw new Exception ("new exercise?");
	$row = array();
	$row["id"] = $id;
	$row["username"] = $userName;
	$row["exercise"] = $exercise->saveXML();
	$row["questionLanguages"] = mysql_real_escape_string( implode( ",", $exercise->getQuestionLanguages() ) );
	$row["answerLanguages"] = mysql_real_escape_string( implode( ",", $exercise->getAnswerLanguages() ) );

	DBTools::unsafe_insert_assoc( "exercises", "id", $id, $row );
	$exercise->setId( mysql_insert_id() ); # might be useful to prevent repeats
	}
コード例 #3
0
	/** similar to above, except *nothing* is escaped.
	 * beware of all kinds of evil injection.
	 */
	public static function unsafe_insert_assoc( $table, $keyfield, $key, $array ) {
		
		$exists = array();
		if ( $key != "" ) {
			$exists = DBTools::doMultirowQuery( "SELECT $keyfield FROM $table WHERE $keyfield=$key" );
		}
		if ( sizeof( $exists ) > 0 ) {
			DBTools::mysql_update_assoc( $table, $array, "WHERE $keyfield='$key'" );
		} else {
			DBTools::mysql_insert_assoc( $table, $array );
		}

	}