Различия
Здесь показаны различия между двумя версиями данной страницы.
| Предыдущая версия справа и слева Предыдущая версия Следующая версия | Предыдущая версия | ||
|
comet:cometql:cli [2015/08/08 16:25] levhav |
comet:cometql:cli [2019/12/18 02:05] (текущий) |
||
|---|---|---|---|
| Строка 2: | Строка 2: | ||
| Расположена в правом нижнем углу экрана на всех старицах этого сайта. | Расположена в правом нижнем углу экрана на всех старицах этого сайта. | ||
| - | Ниже приведён исходный код бэкенд части командной строки. Он не очень то сложный и вполне подходит как пример использования CometQL в PHP | + | Исходный код бэкенд части командной строки смотрите в [[https://github.com/CppComet/CometQL-cli|github репозитории]]. Он не очень то сложный и вполне подходит как пример использования CometQL в PHP |
| - | <code 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"); | + | |
| - | + | ||
| - | $result = mysqli_query ( $link, $_GET["query"] ); | + | |
| - | + | ||
| - | echo "CometQL>".htmlspecialchars($_GET["query"])."<br>"; | + | |
| - | if(mysqli_errno($link) != 0) | + | |
| - | { | + | |
| - | echo "<b>Error code:".mysqli_errno($link)."  Error text:".mysqli_error($link)."</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 ); | + | |
| - | </code> | + | |
| - | + | ||
| - | И фронтенд часть, если вдруг нужна. | + | |
| - | <code html> | + | |
| - | <script> | + | |
| - | 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); | + | |
| - | + | ||
| - | } | + | |
| - | }); | + | |
| - | } | + | |
| - | + | ||
| - | jQuery(document).ready(function(){ | + | |
| - | getCometQL_Form(jQuery("#CometQL-cli")); | + | |
| - | }) | + | |
| - | </script> | + | |
| - | <style> | + | |
| - | #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; | + | |
| - | } | + | |
| - | </style> | + | |
| - | <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> | + | |
| - | </code> | + | |