mysql - Creating a php web server in XAMPP -


i trying create web server in php of xampp php has errors; changed localhost port 80 85 have added mysql database phpmyadmin. don't know why getting error

fatal error: class 'mysql' not found in c:\xampp\htdocs\chitchat\index.php on line 7

<?php //must change below variables ones $dbhost = "localhost:85"; $dbusername = "root"; $dbpassword = ""; $dbname = "chitchat"; $db = new mysql($dbhost,$dbusername,$dbpassword,$dbname); // if operation failed unknown reason define("failed", 0); define("successful", 1); // when  signing up, if username taken, return error define("sign_up_username_crashed", 2);   // when add new friend request, if friend not found, return error  define("add_new_username_not_found", 2); // time_interval_for_user_status: if last authentication time of user    older  // - time_interval_for_user_status, user considered offline define("time_interval_for_user_status", 60); define("user_approved", 1); define("user_unapproved", 0); $username = (isset($_request['username']) && count($_request['username']) > 0)                          ? $_request['username']                          : null; $password = isset($_request['password']) ? md5($_request['password']) : null; $port = isset($_request['port']) ? $_request['port'] : null; $action = isset($_request['action']) ? $_request['action'] : null; if ($action == "testwebapi")  { if ($db->testconnection()){ echo successful; exit; }else{ echo failed; exit; } } if ($username == null || $password == null)   { echo failed; exit; } $out = null; error_log($action."\r\n", 3, "error.log"); switch($action)  {  case "authenticateuser":       if ($userid = authenticateuser($db, $username, $password))      {                             // providerid , requestid id of  friend pair,         // providerid id of making first friend request         // requestid id of friend approved friend request      made providerid          // fetching friends,          // left join expression bit different,          //      required fetch friend, not users          $sql = "select u.id, u.username, (now()-u.authenticationtime) authenticatetimedifference, u.ip,                                      f.providerid, f.requestid, f.status, u.port                          friends f                         left join users u on                                      u.id = if ( f.providerid = ".$userid.", f.requestid, f.providerid )                          (f.providerid = ".$userid." , f.status=".user_approved.")  or                                       f.requestid = ".$userid." ";          //$sqlmessage = "select * `messages` `touid` = ".$userid." , `read` = 0 limit 0, 30 ";          $sqlmessage = "select m.id, m.fromuid, m.touid, m.sentdt, m.read, m.readdt, m.messagetext, u.username messages m \n" . "left join users u on u.id = m.fromuid `touid` = ".$userid." , `read` = 0 limit 0, 30 ";           if ($result = $db->query($sql))                  {                 $out .= "<data>";                  $out .= "<user userkey='".$userid."' />";                 while ($row = $db->fetchobject($result))                 {                     $status = "offline";                     if (((int)$row->status) == user_unapproved)                     {                         $status = "unapproved";                     }                     else if (((int)$row->authenticatetimedifference) < time_interval_for_user_status)                     {                         $status = "online";                      }                     $out .= "<friend  username = '".$row->username."'  status='".$status."' ip='".$row->ip."' userkey = '".$row->id."'  port='".$row->port."'/>";                                              // increase security, need change userkey periodically , pay more attention                                             // receiving message , sending message                   }                     if ($resultmessage = $db->query($sqlmessage))                                    {                         while ($rowmessage = $db->fetchobject($resultmessage))                             {                             $out .= "<message  from='".$rowmessage->username."'  sendt='".$rowmessage->sentdt."' text='".$rowmessage->messagetext."' />";                             $sqlendmsg = "update `messages` set `read` = 1, `readdt` = '".date("y-m-d h:i")."' `messages`.`id` = ".$rowmessage->id.";";                             $db->query($sqlendmsg);                             }                         }                 $out .= "</data>";         }         else         {             $out = failed;         }                }     else     {             // exit application if not authenticated user             $out = failed;     }    break;  case "signupuser":     if (isset($_request['email']))     {          $email = $_request['email'];                  $sql = "select id  users                          username = '".$username."' limit 1";             if ($result = $db->query($sql))          {                 if ($db->numrows($result) == 0)                  {                         $sql = "insert users(username, password, email)                             values ('".$username."', '".$password."', '".$email."') ";                                                        error_log("$sql", 3 , "error_log");                         if ($db->query($sql))                            {                                 $out = successful;                         }                                        else {                                 $out = failed;                         }                                            }                 else                 {                     $out = sign_up_username_crashed;                 }          }                           }     else     {         $out = failed;     }    break;  case "sendmessage": if ($userid = authenticateuser($db, $username, $password))      {        if (isset($_request['to']))     {          $tousername = $_request['to'];           $message = $_request['message'];              $sqlto = "select id  users username = '".$tousername."' limit 1";                    if ($resultto = $db->query($sqlto))                          {                     while ($rowto = $db->fetchobject($resultto))                     {                         $uto = $rowto->id;                     }                     $sql22 = "insert `messages` (`fromuid`, `touid`, `sentdt`, `messagetext`) values ('".$userid."', '".$uto."', '".date("y-m-d h:i")."', '".$message."');";                                                     error_log("$sql22", 3 , "error_log");                         if ($db->query($sql22))                          {                                 $out = successful;                         }                                        else {                                 $out = failed;                         }                                            $resultto = null;                 }         $sqlto = null;     }     }     else     {         $out = failed;     }    break;  case "addnewfriend":     $userid = authenticateuser($db, $username, $password);     if ($userid != null)     {          if (isset($_request['friendusername']))                  {                             $friendusername = $_request['friendusername'];               $sql = "select id users                               username='".$friendusername."'                               limit 1";              if ($result = $db->query($sql))              {                     if ($row = $db->fetchobject($result))                     {                          $requestid = $row->id;                           if ($row->id != $userid)                          {                                  $sql = "insert friends(providerid, requestid, status)                                      values(".$userid.", ".$requestid.", ".user_unapproved.")";                                   if ($db->query($sql))                                  {                                         $out = successful;                                  }                                  else                                  {                                         $out = failed;                                  }                         }                         else                         {                             $out = failed;  // user add friend                         }                                                                     }                     else                     {                         $out = failed;                                           }              }                                             else              {                     $out = failed;              }                       }         else         {                 $out = failed;         }                }     else     {         $out = failed;     }    break;  case "responseoffriendreqs":     $userid = authenticateuser($db, $username, $password);     if ($userid != null)     {         $sqlapprove = null;         $sqldiscard = null;         if (isset($_request['approvedfriends']))         {               $friendnames = split(",", $_request['approvedfriends']);               $friendcount = count($friendnames);               $friendnamesquerypart = null;               ($i = 0; $i < $friendcount; $i++)               {                 if (strlen($friendnames[$i]) > 0)                 {                     if ($i > 0 )                     {                         $friendnamesquerypart .= ",";                     }                      $friendnamesquerypart .= "'".$friendnames[$i]."'";                  }                               }               if ($friendnamesquerypart != null)               {                 $sqlapprove = "update friends set status = ".user_approved."                                 requestid = ".$userid." ,                                              providerid in (select id users username in (".$friendnamesquerypart."));                             ";                     }          }         if (isset($_request['discardedfriends']))         {                 $friendnames = split(",", $_request['discardedfriends']);               $friendcount = count($friendnames);               $friendnamesquerypart = null;               ($i = 0; $i < $friendcount; $i++)               {                 if (strlen($friendnames[$i]) > 0)                 {                     if ($i > 0 )                     {                         $friendnamesquerypart .= ",";                     }                      $friendnamesquerypart .= "'".$friendnames[$i]."'";                  }                                  }               if ($friendnamesquerypart != null)               {                 $sqldiscard = "delete friends                                      requestid = ".$userid." ,                                                  providerid in (select id users username in (".$friendnamesquerypart."));                                         ";               }                              }         if (  ($sqlapprove != null ? $db->query($sqlapprove) : true) &&                     ($sqldiscard != null ? $db->query($sqldiscard) : true)             )         {             $out = successful;         }         else         {             $out = failed;         }            }     else     {         $out = failed;     } break;  default:     $out = failed;           break;   } echo $out; /////////////////////////////////////////////////////////////// function authenticateuser($db, $username, $password) {  $sql22 = "select * users                  username = '".$username."' , password = '".$password."'                  limit 1";  $out = null; if ($result22 = $db->query($sql22)) {     if ($row22 = $db->fetchobject($result22))     {             $out = $row22->id;              $sql22 = "update users set authenticationtime = now(),                                                               ip = '".$_server["remote_addr"]."' ,                                                              port = 15145                              id = ".$row22->id."                             limit 1";              $db->query($sql22);                    }        }  return $out; } ?> 

sql code:

create table [if not exists] friends ( id int (10) not null auto_increment, providerid int(10) not null auto_increment, requestid int(10) not null auto_increment, status binary(1) not null default primary key (id));  create table [if not exists] messages ( id int(255) not null auto_increment, fromuid int(255) not null, touid int(255) not null, sentdt datetime not null; read tinyint(1) not null default '0', readdt datetime default null, messagetext longtext character set utf8 | not null, primary key (id) )   create table [if not exists] users (     id int(10) unsigned not null auto_increment,     username varchar(45) not null default '',     password varchar(32) not null default '',     email varchar(45) not null default '',     date datetime not null default '0000-00-00 00:00:00',     status tinyint(3) unsigned not null default '0',     authenticationtime datetime not null default '0000-00-00 00:00:00',    userkey varchar(32) not null default '', ip varchar(45) not null default '',  port int(10) unsigned not null default '0', primary key (id) ) 

change line

        $db = new mysql($dbhost,$dbusername,$dbpassword,$dbname); 

to

        $db = new mysqli($dbhost,$dbusername,$dbpassword,$dbname); 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -