MT4-通过PHP连接Mysql


MT4 - Mysql connection via PHP

我需要从MT4向Mysql数据库获取/发送数据。我使用了"libmysql.dll"或mysql_wrapper(也基于libmysql.dll),但它似乎不稳定。

我想我可以使用PHP作为服务器(在指定端口创建TCP/IP套接字),使用MT4 EA/脚本作为客户端。或者使用Apache作为服务器(创建PHP脚本来完成Mysql连接),使用MT4 EA/screp作为客户端。

因此,PHP是MT4&Mysql。PHP从MT4获得请求,连接到Mysql(如果需要,可以进行计算),然后将结果发送回MT4。你能给我一个在Windows XP中如何做到这一点的线索吗(我的Windows XP上安装了Apache、PHP和Mysql)?

谢谢插孔

我得到了这个PHP脚本,它打开了一个特定的端口,并等待连接。我可以使用Telnet连接到它。任何人都知道如何使用MQL4连接到那个端口吗?

感谢

// usage example in command prompt: telnet 192.168.7.21  168168 
// To quit, type: quit 
// To shutdown PHP server, type: shutdown // //
// **************************************************************

<?php error_reporting(E_ALL);
/* Allow the script to hang around waiting for connections. */ set_time_limit(0);
/* Turn on implicit output flushing so we see what we're getting  * as it comes in. */ ob_implicit_flush();
$address = '192.168.7.21'; $port = 168168;
if (($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) === false) {
    echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "'n"; }
if (socket_bind($sock, $address, $port) === false) {
    echo "socket_bind() failed: reason: " . socket_strerror(socket_last_error($sock)) . "'n"; }
if (socket_listen($sock, 5) === false) {
    echo "socket_listen() failed: reason: " . socket_strerror(socket_last_error($sock)) . "'n"; }
do {
    if (($msgsock = socket_accept($sock)) === false) {
        echo "socket_accept() failed: reason: " . socket_strerror(socket_last_error($sock)) . "'n";
        break;
    }
    /* Send instructions. */
    $msg = "'nWelcome to the PHP Test Server. 'n" .
        "To quit, type 'quit'. To shut down the server type 'shutdown'.'n";
    socket_write($msgsock, $msg, strlen($msg));
    do {
        if (false === ($buf = socket_read($msgsock, 2048, PHP_NORMAL_READ))) {
            echo "socket_read() failed: reason: " . socket_strerror(socket_last_error($msgsock)) . "'n";
            break 2;
        }
        if (!$buf = trim($buf)) {
            continue;
        }
        if ($buf == 'quit') {
            break;
        }
        if ($buf == 'shutdown') {
            socket_close($msgsock);
            break 2;
        }
        $talkback = "PHP server: You said '$buf'.'n";
        socket_write($msgsock, $talkback, strlen($talkback));
        echo "$buf'n";
    } while (true);
    socket_close($msgsock); } while (true);
socket_close($sock); ?>

如果我在你那里,我不会走那条路。。。

也许您应该看看消息队列(AMQP-RabbitMQ-ZeroMQ)。。。

看那个帖子http://worldwide-invest.org/threads/34585-Messaging-queue-AMQP-(RabbitMQ ZeroMQ)-和MT4

您会看到,我可以使用任何语言收集tick数据,并将其存储在支持RabbitMQ的语言支持的任何数据库中(从Python到Java,通过C、C++、C#…)

Metatrader和ZeroMQ(ZMQ)之间还有一座桥梁https://github.com/AustenConrad/mql4zmq

首先,我假设您正在尝试将MT4客户端(而不是服务器)连接到MySQL数据库。否则,就没有理由存在稳定问题。如果你使用EA连接到数据库,只需小心处理连接,EA不是标准的可执行文件,EA内部的代码在每个"刻度"上都会运行,所以要考虑到这一点。相信我,当事情如此简单的时候,把PhP放在中间只会使事情变得复杂(并显著降低性能!)。如果我们能提供任何帮助,请告诉我们:www.mt4software.com