PHPize Online / SQLize Online

A A A
Share   Donate   Blog   Popular
Copy Format Clear
CREATE TABLE `chat` ( `msgId` int(11) NOT NULL AUTO_INCREMENT, `msgFrom` varchar(255) NOT NULL, `msgChatId` varchar(255) NOT NULL, `msgText` mediumtext NOT NULL, PRIMARY KEY (`msgId`) ); INSERT INTO chat (msgChatId, msgFrom, msgText) VALUES('123', 'worker', 'test'); INSERT INTO chat (msgChatId, msgFrom, msgText) VALUES('123', 'worker', 'test 2'); INSERT INTO chat (msgChatId, msgFrom, msgText) VALUES('456', 'worker', 'test'); INSERT INTO chat (msgChatId, msgFrom, msgText) VALUES('123', 'client', 'test client');
Copy
Copy Format Clear
<?php $msgChatId = 123; $sth = $pdo->prepare('SELECT msgFrom, msgText FROM chat WHERE msgChatId = :msgChatId'); $sth->bindParam('msgChatId', $msgChatId, PDO::PARAM_STR); $sth->execute(); $res = $sth->fetchAll(); foreach($res as $message) { echo $message['msgFrom'].': '.$message['msgText']; }
Show:  
Copy