Различия
Здесь показаны различия между двумя версиями данной страницы.
Предыдущая версия справа и слева Предыдущая версия | |||
comet:cometql:cli [2015/08/12 11:35] levhav |
comet:cometql:cli [2017/04/20 09:48] levhav |
||
---|---|---|---|
Строка 2: | Строка 2: | ||
Расположена в правом нижнем углу экрана на всех старицах этого сайта. | Расположена в правом нижнем углу экрана на всех старицах этого сайта. | ||
- | Ниже приведён исходный код бэкенд части командной строки. Он не очень то сложный и вполне подходит как пример использования CometQL в PHP | + | Исходный код бэкенд части командной строки смотрите в [[https://github.com/CppComet/CometQL-cli|github репозитории]]. Он не очень то сложный и вполне подходит как пример использования CometQL в PHP |
- | <file php CometQL-cli.php> | + | |
- | <?php | + | |
- | + | ||
- | header("Content-Type: text/html; charset=utf-8"); | + | |
- | + | ||
- | ini_set('display_errors','on'); | + | |
- | error_reporting(E_ALL); | + | |
- | + | ||
- | $link = mysqli_connect("app.comet-server.ru", "15", "lPXBFPqNg3f661JcegBY0N0dPXqUBdHXqj2cHf04PZgLHxT6z55e20ozojvMRvB8", "CometQL_v1"); | + | |
- | if ( !$link ) die ("Невозможно подключение к CometQL"); | + | |
- | + | ||
- | if( !isset($_GET["query"]) || empty($_GET["query"])) | + | |
- | { | + | |
- | echo "Параметр query не задан."; | + | |
- | exit(); | + | |
- | } | + | |
- | + | ||
- | $result = mysqli_query ( $link, $_GET["query"] ); | + | |
- | + | ||
- | echo "CometQL>".htmlspecialchars($_GET["query"])."<br>\n"; | + | |
- | if(mysqli_errno($link) != 0) | + | |
- | { | + | |
- | echo "<b>Error code:<a href='https://comet-server.ru/wiki/doku.php/comet:cometql:error' target='_blank' >".mysqli_errno($link)."</a>  Error text:<a href='https://comet-server.ru/wiki/doku.php/comet:cometql:error' target='_blank' >".mysqli_error($link)."</a></b>"; | + | |
- | } | + | |
- | else if(@mysqli_num_rows($result)) | + | |
- | { | + | |
- | $row = mysqli_fetch_assoc($result); | + | |
- | echo "<table>\n"; | + | |
- | echo "\t<tr>\n"; | + | |
- | foreach ($row as $key => $value) | + | |
- | { | + | |
- | echo "\t\t<td>".$key."</td>\n"; | + | |
- | } | + | |
- | echo "\t</tr>\n"; | + | |
- | do | + | |
- | { | + | |
- | echo "\t<tr>\n"; | + | |
- | foreach ($row as $key => $value) | + | |
- | { | + | |
- | echo "\t\t<td>".htmlspecialchars($value)."</td>\n"; | + | |
- | } | + | |
- | echo "\t</tr>\n"; | + | |
- | }while($row = mysqli_fetch_assoc($result)); | + | |
- | echo "</table>\n"; | + | |
- | echo "<b>".mysqli_num_rows($result)." rows in set</b>\n"; | + | |
- | } | + | |
- | else | + | |
- | { | + | |
- | echo "<b>Empty set</b>\n"; | + | |
- | } | + | |
- | + | ||
- | echo "<hr>"; | + | |
- | + | ||
- | mysqli_close ( $link ); | + | |
- | </file> | + | |
- | + | ||
- | И фронтенд часть, если вдруг нужна. | + | |
- | <file JavaScript CometQL-cli.js> | + | |
- | function send_cometQL_query(text) | + | |
- | { | + | |
- | jQuery.ajax({ | + | |
- | url: "http://comet-server.ru/doc/CometQL/commander/index.php?query="+encodeURIComponent(text), | + | |
- | type: "GET", | + | |
- | success: function(data) | + | |
- | { | + | |
- | jQuery("#CometQL-cli-reslog").append(data).scrollTop(999999); | + | |
- | + | ||
- | } | + | |
- | }); | + | |
- | } | + | |
- | </file> | + | |
- | <file css CometQL-cli.css> | + | |
- | #CometQL-cli | + | |
- | { | + | |
- | display:none; | + | |
- | position: fixed; | + | |
- | bottom: 0px; | + | |
- | right: 20px; | + | |
- | background-color: #fff; | + | |
- | padding: 10px; | + | |
- | border: 1px solid; | + | |
- | z-index: 30; | + | |
- | box-shadow: 0 0 10px #222; | + | |
- | } | + | |
- | + | ||
- | #CometQL-cli-text | + | |
- | { | + | |
- | margin-bottom: 5px; | + | |
- | margin-top: 5px; | + | |
- | } | + | |
- | + | ||
- | #CometQL-cli-text textarea | + | |
- | { | + | |
- | padding: 3px; | + | |
- | font-family: Courier New,Courier,Lucida Sans Typewriter,Lucida Typewriter,monospace; | + | |
- | max-height: 40px; | + | |
- | height: 40px; | + | |
- | min-width: 460px; | + | |
- | max-width: 1600px; | + | |
- | margin-right: 5px; | + | |
- | } | + | |
- | + | ||
- | .CometQL-button | + | |
- | { | + | |
- | padding: 3px; | + | |
- | font-family: Courier New,Courier,Lucida Sans Typewriter,Lucida Typewriter,monospace; | + | |
- | float: right; | + | |
- | height: 40px; | + | |
- | width: 40px; | + | |
- | } | + | |
- | + | ||
- | #CometQL-cli-reslog{ | + | |
- | overflow: auto; | + | |
- | height: 300px; | + | |
- | border: 1px solid #ccc; | + | |
- | background-color: #fafafa; | + | |
- | font-family: Courier New,Courier,Lucida Sans Typewriter,Lucida Typewriter,monospace; | + | |
- | padding: 10px; | + | |
- | max-width: 1600px; | + | |
- | } | + | |
- | + | ||
- | #CometQL-cli-Header a{ | + | |
- | float:right; | + | |
- | } | + | |
- | + | ||
- | #CometQL-cli-open{ | + | |
- | position: fixed; | + | |
- | bottom: 0px; | + | |
- | right: 20px; | + | |
- | background-color: #fff; | + | |
- | padding: 10px; | + | |
- | border: 1px solid; | + | |
- | z-index: 30; | + | |
- | box-shadow: 0 0 10px #222; | + | |
- | cursor: pointer; | + | |
- | } | + | |
- | </file> | + | |
- | <file html CometQL-cli.html> | + | |
- | <div id="CometQL-cli"> | + | |
- | + | ||
- | <div id='CometQL-cli-Header'>CometQL командная строка с демо доступом <a href="" onclick="jQuery('#CometQL-cli').hide(); jQuery('#CometQL-cli-open').show(); return false;" >[X]</a></div> | + | |
- | <div id='CometQL-cli-text'> | + | |
- | <textarea id='cometQL-query-text' >SELECT * FROM pipes_messages WHERE name = "pipe1";</textarea> | + | |
- | <button class="CometQL-button" onclick='send_cometQL_query(jQuery("#cometQL-query-text").val())'>OK</button> | + | |
- | </div> | + | |
- | <div id='CometQL-cli-reslog'></div> | + | |
- | </div> | + | |
- | <div id="CometQL-cli-open" onclick="jQuery('#CometQL-cli').show(); jQuery('#CometQL-cli-open').hide();" > | + | |
- | CometQL командная строка с демо доступом. | + | |
- | </div> | + | |
- | </file> | + |