0

I need to get/send data from MT4 from/to Mysql database. I used "libmysql.dll" or mysql_wrapper (also based on libmysql.dll), but it seems not stable.

I think may be i can use PHP as server (creating TCP/IP socket at a specified port) and MT4 EA/script as client. Or maybe using Apache as server (creating PHP scripts to do the job for Mysql connection) and MT4 EA/scrip as client.

So, PHP is a bridge between MT4 & Mysql. PHP get request from MT4, connect to Mysql (and do calculation if needed), then send the result back to MT4. Could you please give me a clue how to do it in Windows XP (I have Apache, PHP, Mysql installed on my Windows XP) ?

Thanks jack

user2758001
  • 109
  • 4
  • 11

3 Answers3

0

i got this PHP script that open a specific port, and waiting for connection. I can use Telnet to connect to it. Any body know how to connect to that port using MQL4 ?

Thanks

// 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); ?>
user2758001
  • 109
  • 4
  • 11
0

If I where you I will not go that way...

Maybe you should have a look at messaging queues (AMQP - RabbitMQ - ZeroMQ)...

See that post http://worldwide-invest.org/threads/34585-Messaging-queue-AMQP-(RabbitMQ-ZeroMQ)-and-MT4

You will see that I can collect tick data using any language and store them in any database supported by language which supports RabbitMQ (a lot from Python to Java via C, C++, C# ...) .

There is also a bridge between Metatrader and ZeroMQ (ZMQ) https://github.com/AustenConrad/mql4zmq

Femto Trader
  • 1,932
  • 2
  • 20
  • 25
0

First, I am assuming you are trying to connect MT4 Client Terminal (not Server) to a MySQL database. Otherwise, there is no reason for stability issues to exist. If you are using an EA to connect to a database, just handle connections carefully, an EA is not a standard executable, the code inside an EA is run on every 'tick', so take that into account. Trust me, putting PhP in the middle is just complicating things when they are so simple (and lowering performance significantly!). If we can be of any help, let us know: www.mt4software.com

mboullra
  • 11
  • 4