Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved]Getting SQL Database info to print through a php server and a Qt socket
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 5.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    webmaster.skelton
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      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?

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • W Offline
        W Offline
        webmaster.skelton
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0
        • V Offline
          V Offline
          vcsala
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • W Offline
            W Offline
            webmaster.skelton
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • W Offline
              W Offline
              webmaster.skelton
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                seeyousystems
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                • W Offline
                  W Offline
                  webmaster.skelton
                  wrote on last edited by
                  #8

                  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.

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved