PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      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 (msgFrom, msgChatId, msgText) VALUES('123', 'worker', 'test'); INSERT INTO chat (msgFrom, msgChatId, msgText) VALUES('123', 'worker', 'test 2'); INSERT INTO chat (msgFrom, msgChatId, msgText) VALUES('456', 'worker', 'test'); INSERT INTO chat (msgFrom, msgChatId, msgText) VALUES('123', 'client', 'test client');
Copy Clear
Copy Format Clear
<?php $msgChatId = 123; $test = $pdo->prepare('SELECT msgFrom, msgText FROM chat WHERE msgChatId = :msgChatId'); $test = $test->bindParam('msgChatId', $msgChatId, PDO::PARAM_STR); $res = $test->exec(); foreach($res as $message) { echo $message['msgFrom'].': '.$message['msgText']; }
Show:  
Copy Clear