Jump to content

Recommended Posts

Posted

Here is a "short" example of how you can read text from a mysql database with autoit and php

hmm where should i start to explain this :lmao:

im looking each time if there is a new entry in the database

with:

InetGet( $url & "getid.php?user_id=" & $php_id, $textfile, 1, 0 )

if there is a new request, in the file downloaded will be the mysql database id

else if there is no new request the file will be blank and the loop goes on

id found:

with

InetGet( $url & "unset.php?user_id=" & $php_id & "&id=" & $id & "&prozess=1&stat=read", $textfile, 1, 0 )

i get the text out of the database and flag it to be in progress

it does the suff you want and the sets the prozess to finished

InetGet( $url & "unset.php?user_id=" & $php_id & "&id=" & $id & "&prozess=2", $textfile, 1, 0 )

example.au3

Opt("TrayIconHide", 0)

Global $url = "http://www.mypage.at/example/"
Global $Windowname = "AutoIt with Php Mysql Example"

Global $textfile = "example_temp.txt"
Global $php_id = "a56076518"

While 1
   InetGet( $url & "getid.php?user_id=" & $php_id, $textfile, 1, 0 ) ;gets the next request id from the mysql database
   $file = FileOpen($textfile, 0)
   $id = FileReadLine($file, 1)
   
   FileClose($file)
   FileDelete($textfile)
   
   If ( StringIsInt($id) ) Then
      
      InetGet( $url & "unset.php?user_id=" & $php_id & "&id=" & $id & "&prozess=1&stat=read", $textfile, 1, 0 );reads the request from the database at id above taken and sets status to 1 = starting
      
      $file = FileOpen($textfile, 0);reads request
      
      $au3 = FileReadLine($file, 1);request.au3
      
      FileClose($file)
      FileDelete($textfile)
      
      If ( $au3 == "somefuncname") Then
         MsgBox ( 0, $Windowname, "put a function here", 5 )
      Else
         MsgBox ( 0, $Windowname, "text from db: " & $au3, 5 )
      EndIf
      
      Sleep(3000)
      
      InetGet( $url & "unset.php?user_id=" & $php_id & "&id=" & $id & "&prozess=2", $textfile, 1, 0 ) ;sets the status of the commands to 2 = finished
      FileDelete($textfile)
   Else
      Sleep(5000)
   EndIf
WEnd

getid.php

<?
    if ( $_REQUEST["user_id"] == "a56076518" ) {
        
        $sql = "SELECT id FROM ".PREFIX."prozess WHERE prozessed = 0 ORDER BY time";
        $result = $db->query($sql);
        
        $rows = mysql_num_rows($result);
        
        if ( $rows == 0 ) {
            echo "";
        } else {
            $rows = mysql_fetch_row($result);
            echo $rows[0];
        }
    }
?>

unset.php

<?
    if ( $_REQUEST["user_id"] == "a56076518" ) {
        
        $stat = $_REQUEST["prozess"];
        $id = $_REQUEST["id"];
        
        $sql = "UPDATE ".PREFIX."prozess SET prozessed = '$stat' WHERE id = $id";
        $result = $db->query($sql);
        
        if ( $_REQUEST["stat"] == "read" ) {
            $sql = "SELECT au3 FROM ".PREFIX."prozess WHERE id = $id";
            
            $explode = mysql_fetch_row($db->query($sql));
            
            echo $explode[0];
        }
    }
?>

i made a example web page ..

just upload it somewhere php and mysql works

edit the settings.inc.php in the includes folder

just change at the mysql section

$server = "localhost";

$user = "user";

$password = "pass";

$database = "db";

that the script has access

change the

Global $url = "http://www.mypage.at/example/"

in the example.au3

then run it

start the webpage index.php

write some text in click send an it will be shown in a msgbox

have fun

example.zip

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...