Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class DataManager {
- public $con;
- function __construct(){
- $this->con = mysql_connect("localhost","forum","forum");
- if (!$this->con) {
- die('Could not connect: ' . mysql_error());
- }
- mysql_select_db("scm", $this->con);
- }
- function getIdUser($name){
- $name = mysql_escape_string($name);
- $result = mysql_query("select id from user where name like '".$name."'");
- $ar = array();
- while($row = mysql_fetch_array($result)) $ar[] = $row;
- return $ar[0][0];
- }
- function getNameUser($id){
- $id = mysql_escape_string($id);
- $result = mysql_query("select name from user where id=".$id);
- $ar = array();
- while($row = mysql_fetch_array($result)) $ar[] = $row;
- return $ar[0][0];
- }
- function post($thid,$text){
- $text = mysql_escape_string($text);
- $text = str_replace("<","<",$text);
- $text = str_replace(">",">",$text);
- if (strlen($text)>0){
- $x = "insert into post(user,date,text,thread) values(".$_SESSION['user'].",NOW(),\"".$text."\",".$thid.")";
- if (!mysql_query($x)) {
- return false;
- }
- return true;
- }
- return false;
- }
- function register($user,$pass){
- $user = mysql_escape_string($user);
- $user = str_replace("<","<",$user);
- $user = str_replace(">",">",$user);
- if (strlen($user)>0){
- $pass = mysql_escape_string($pass);
- $pass = str_replace("<","<",$pass);
- $pass = str_replace(">",">",$pass);
- $result = mysql_query("select count(*) as c from user where name='".$user."'");
- $ar = array();
- while($row = mysql_fetch_array($result))$ar[] = $row;
- if ($ar[0]['c'] != 0) return false;
- $x = "insert into user(name,password) values('".$user."','".md5($user.'|'.$pass)."');";
- if (!mysql_query($x)) {
- return false;
- }
- return true;
- }
- return false;
- }
- function newThread($name,$user){
- $name = mysql_escape_string($name);
- $name = str_replace("<","<",$name);
- $name = str_replace(">",">",$name);
- if (strlen($user)>0){
- $x = "insert into threads(name,creation_date,user) values('".$name."',NOW(),".$user.");";
- if (!mysql_query($x)) {
- return false;
- }
- return true;
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement