Hi I'm currently developing a chat support in PHP that involves 2 database one is for the compilation of all the conversations that have been added now each tables are named after 2 users that have converse the other one is for storing the chat logs between the two inside it is the timestamp the msgid and the sender and the reciever
the other database is for storing the details for the 2nd database now I'm kinda stuck on how do I insert the message after its table has been created, here is my script so far
//inserting chat conv good for 1 week
$sql4="INSERT INTO thread(msgid, startedby, participant, creation_date) VALUES ( :msgid ,:startedby,:participant,NOW())";
$prep=$con->prepare($sql4);
$prep->bindParam(':msgid',$msguser,PDO::PARAM_STR);
$prep->bindParam(':startedby',$us1_o,PDO::PARAM_STR);
$prep->bindParam(':participant',$us2_o,PDO::PARAM_STR);
$prep->execute();
//creation of table based on both involve parties
$con2 = new PDO("mysql:host=". DB_host .";dbname=db", DB_username , DB_password);
$con2->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$con2->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$q="CREATE TABLE ". $user1 . $user2 ."chat_log (
modurator varchar(100) NOT NULL,
client varchar(100) NOT NULL,
tstamp int(10) NOT NULL,
msgid varchar(250) NOT NULL,
PRIMARY KEY (msgid)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;
CREATE TABLE ". $user1 . $user2 ."chat_conversation (
msgid varchar(250) NOT NULL,
username varchar(250) NOT NULL,
conversation varchar(250) NOT NULL,
tstamp int(10) NOT NULL,
PRIMARY KEY (msgid)
) ENGINE=MyISAM DEFAULT CHARSET=latin1";
try {
$con2->exec($q) or die($con2->errorInfo());
echo "Success";
//insert of chat conv
} catch (PDOException $e) {
$e->getMessage();
}
$sql5="INSERT INTO ". $user1 . $user2 ."chat_conversation(msgid, username,conversation,tstamp) VALUES ( :msgid ,:username,:msg,NOW())";
$prep2= $con2->prepare($sql5);
$prep2->bindParam(':msgid',$msguser,PDO::PARAM_STR);
$prep2->bindParam(':username',$usern,PDO::PARAM_STR);
$prep2->bindParam(':msg',$txt,PDO::PARAM_STR);
$prep2->execute();
}
the reason behind why I want to insert the data as soon as its newly created is because my boss wants it to be in real time which is why some of the variables are called using ajax
This was called using a class btw
You need some push functionality for stuff like that. PHP does not support web sockets or something like that, but you can use services that do it for you. Two examples of services that do something like that are http://pusher.com and http://pubnub.com.