[solved]Getting SQL Database info to print through a php server and a Qt socket



  • OK so here is my issue. I need to be able to read data in from an SQL database into php( where my server is created) and from the php i need to pass it back through a QTcpSocket and print it to a console. I have checked my php and i am obtaining the data from the table, but on the Qt application side it will not print to the screen. I have bee able to grab strings in the php and print them to the app screen, but when i try to grab the data from my database, nothing prints. Here is some example code:

    Qt side:

    @

    sock.write("GET_DECRYPT");
    sock.waitForReadyRead(1000);
    
    QByteArray messageBytes3 = sock.read(512);
    
     QString message3(messageBytes3);
    
     cout<< message3.toStdString() <<endl;
     sock.flush();
    

    @

    php side:

    @
    CASE 'GET_DECRYPT':
    rLog("Client #".$i." requested a policy file...");
    $q = mysql_query("SELECT * FROM SocketTest");
    &data = mysql_fetch_array($q);
    $cdmp = $data[0];
    /// blah blah some echo stuff
    socket_write($client[$i]['sock'],$cdmp);
    break;

    @

    so why can i not read it back into my app?



  • Hard to know. Could be that your php socket is buffered and needs some flush. socket_write() returns the bytes written - is that value greater than 0?



  • the socket is not buffered on the php side, and the value is greater than zero. I can print_f($data) and get the info stored in the database so know the query is returning the data, but when i try to write it to the console on the app side, it simply does not display anything. So im makeing the assumption that its not reading back into the app properly, do you see anything in my read that could cause problems?



  • Can you check if waitForReadyRead returns true or false? If any error happens it returns false and errorString contains the error message.



  • its returning true so i am not sure what exaclty is causing the problem. I can read anything else from the server, but when i try to get the info from the database it does not read it.



  • ok I found my problem, and error in code that i didnt post. Thanks for the help though. I would not have found it without it.



  • Hello webmaster.skelton,

    I am working with a similar project. Is there any way you can post your code to see how it works?

    Abraham



  • I cant post any more of my code at this point as it is of a proprietary nature. I would be happy to help you out though. What exactly are you having issues with? How much to you have functioning? If you post snippets of your code i may be able to direct you towards the answer. You may also wish to create a new post with your questions as this one is tagged solved and you will not get as much community attention to your issues. Please direct me toward the new post so i can assist.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.