ฟอรั่ม PSsix

Would you like to react to this message? Create an account in a few clicks or log in to continue.

ฟอรั่มของบล็อก http://pssix.blogspot.com


3 posters

    รบกวน ช่วยดู สคริปผมหน่อยครับ

    avatar
    chaodroger
    PSsix Member Class II
    PSsix Member Class II


    รบกวน ช่วยดู สคริปผมหน่อยครับ Empty รบกวน ช่วยดู สคริปผมหน่อยครับ Empty
    จำนวนข้อความ : 30
    ความนิยม : 0
    เข้าร่วมเมื่อ : 30/12/2013

    รบกวน ช่วยดู สคริปผมหน่อยครับ Empty รบกวน ช่วยดู สคริปผมหน่อยครับ

    ตั้งหัวข้อ by chaodroger 15/02/14, 11:38 pm

    Code:
    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>

       $Form2 = GUICreate("Child window is still here", 377, 212, 192, 124)
       $Username = GUICtrlCreateInput("Username", 64, 72, 209, 21)
       $Password = GUICtrlCreateInput("Password", 64, 104, 209, 21)
       $Button2 = GUICtrlCreateButton("Button", 136, 136, 73, 33, $WS_GROUP)
       GUISetState(@SW_SHOW)
       While 1
          $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
             Case $Button2
                $ReadingUsername = GUICtrlRead($Username)
                $ReadingPassword = GUICtrlRead($Password)
                If $ReadingUsername = "user1" And $ReadingPassword = "password1" Then
                   MsgBox(0,"TEST!", "ผ่าน")
                Else
                   MsgBox(0,"TEST!", "ไม่ผ่าน")
                EndIf
        EndSwitch
    WEnd

    ตรง user1/pass1 ผมอยากให้มันดึงข้อมูลจาก ฐานข้อมูล ต้องเขียนคำสั่งยังไงอ่ะครับ... ขอบคุณครับ
    wdiLi
    wdiLi
    PSsix Member High Class
    PSsix Member High Class


    PSsix Game Coder
    จำนวนข้อความ : 73
    ความนิยม : 7
    เข้าร่วมเมื่อ : 29/01/2011
    อายุ : 33

    รบกวน ช่วยดู สคริปผมหน่อยครับ Empty Re: รบกวน ช่วยดู สคริปผมหน่อยครับ

    ตั้งหัวข้อ by wdiLi 16/02/14, 01:29 am

    ต้องเรียกใช้งาน UDF (SQLite) ในการจัดการฐานข้อมูล

    Code:
    #include <SQLite.au3>
    #include <SQLite.dll.au3>

    โค้ด สร้างฐานข้อมูล และสร้างตาราง เพิ่มข้อมูล
    Code:
    #include <SQLite.au3>
    #include <SQLite.dll.au3>
    ; เปิดการใช้งาน sqlite.dll
    _SQLite_Startup()
    ; สร้าง ฐานข้อมูล ชื่อ test.db
    $DB = _SQLite_Open("Test.db")
    ; สร้างตารางชื่อ user มี 3 ฟิลด์ คือ user_id , user_name , user_pass
    _SQLite_Exec ($DB , "CREATE TABLE user (user_id , user_name, user_pass);")
    ; เพิ่มข้อมูลลงตาราง user โดยค่ามีดังนี้ 0001 , admin , 1234
    _SQLite_Exec ($DB , "INSERT INTO user (user_id , user_name, user_pass) VALUES ('0001', 'admin', '1234');")
    ; ปิดการใช้งาน sqlite.dll
    _SQLite_Shutdown()

    โค้ด แสดงข้อมูลจากฐานข้อมูล
    Code:
    #include <SQLite.au3>
    #include <SQLite.dll.au3>
    ; เปิดการใช้งาน sqlite.dll
    _SQLite_Startup()
    Local $Query, $Row
    ; เปิดใช้งาน ฐานข้อมูล Test.db
    $DB = _SQLite_Open("Test.db")
    ; Query คำสั่ง SQL ค้นหาฟิลด์ ทั้งหมดใน Test.db
    _SQLite_Query($DB , "SELECT * FROM user", $Query)
    ; ดึงข้อมูลในฟิลด์ทั้งหมด ออกมาในรูปแบบ Array แล้วเอาข้อมูลมาเก็บไว้ในตัวแปร $Row
    _SQLite_FetchData($Query , $Row)
    ; แสดงข้อมูลออกมา ใส่ MessageBox ดู
    MsgBox(1 , "Info", $Row[0]&" , "&$Row[1]& " , " & $Row[2])
    ; ปิดการใช้งาน sqlite.dll
    _SQLite_Shutdown()

    เมื่อเอาโค้ด SQLite กับ สคริปที่เอามาถาม น่าจะประมาณ นี้นะครับ
    Code:
    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <SQLite.au3>
    #include <SQLite.dll.au3>

    $Form2 = GUICreate("Child window is still here", 377, 212, 192, 124)
    $Username = GUICtrlCreateInput("Username", 64, 72, 209, 21)
    $Password = GUICtrlCreateInput("Password", 64, 104, 209, 21)
    $Button2 = GUICtrlCreateButton("Login", 136, 136, 73, 33, $WS_GROUP)
    GUISetState(@SW_SHOW)

    _SQLite_Startup()
    Local $Query , $Row
    $DB = _SQLite_Open("Test.db")
    _SQLite_Query($DB , "SELECT * FROM user" , $Query)
    _SQLite_FetchData($Query , $Row)
    ConsoleWrite("row : "&$Row[0]&" , "&$Row[1]&" , "&$Row[2]&@CRLF)
    ;~ _SQLite_Close()
    _SQLite_Shutdown()

    While 1
      $nMsg = GUIGetMsg()
    Switch $nMsg
       Case $GUI_EVENT_CLOSE
          Exit
        Case $Button2
          $ReadingUsername = GUICtrlRead($Username)
          $ReadingPassword = GUICtrlRead($Password)
          If $ReadingUsername = $Row[1] And $ReadingPassword = $Row[2] Then
             MsgBox(0,"TEST!", "ผ่าน")
          Else
             MsgBox(0,"TEST!", "ไม่ผ่าน")
          EndIf
    EndSwitch
    WEnd

    พอจะเป็นแนวทาง ให้นะคับ ผมก็ไม่เก่ง ภาษา autoit เท่าไร ถ้าเคยเรียนหรือศึกษา ภาษา SQL มา
    น่าจะพอเข้าใจในระดับหนึ่ง แต่ถ้ามือใหม่จริงๆ คงต้องขยันศึกษาแล้วละคับ ถ้ายากเก่งในทางนี้ ขยันอ่านเยอะๆ
    ค้นหาใน Google , youtube ก็มีเยอะมาก เกี่ยวกับการเขียน สคริป Autoit
    avatar
    chaodroger
    PSsix Member Class II
    PSsix Member Class II


    รบกวน ช่วยดู สคริปผมหน่อยครับ Empty รบกวน ช่วยดู สคริปผมหน่อยครับ Empty
    จำนวนข้อความ : 30
    ความนิยม : 0
    เข้าร่วมเมื่อ : 30/12/2013

    รบกวน ช่วยดู สคริปผมหน่อยครับ Empty Re: รบกวน ช่วยดู สคริปผมหน่อยครับ

    ตั้งหัวข้อ by chaodroger 16/02/14, 02:11 am

    ขอบคุณอีกครั้งนะครับ.. มีอะไรให้ฝึกทำอีกแล้วคืนนี้ อิอิ ><"
    avatar
    chaodroger
    PSsix Member Class II
    PSsix Member Class II


    รบกวน ช่วยดู สคริปผมหน่อยครับ Empty รบกวน ช่วยดู สคริปผมหน่อยครับ Empty
    จำนวนข้อความ : 30
    ความนิยม : 0
    เข้าร่วมเมื่อ : 30/12/2013

    รบกวน ช่วยดู สคริปผมหน่อยครับ Empty Re: รบกวน ช่วยดู สคริปผมหน่อยครับ

    ตั้งหัวข้อ by chaodroger 16/02/14, 06:48 pm

    ให้สคริป คอนเนก ไปหา MํYsQL บน Server ได้มัยครับ แบบ ใส่ ip โฮสไรพวกนี้อ่ะครับ ขอบคุณครับ
    Arm
    Arm
    PSsix Member Super Class III
    PSsix Member Super Class III


    PSsix Master PSsix Program Coder
    จำนวนข้อความ : 268
    ความนิยม : 54
    เข้าร่วมเมื่อ : 31/03/2011
    อายุ : 26

    รบกวน ช่วยดู สคริปผมหน่อยครับ Empty Re: รบกวน ช่วยดู สคริปผมหน่อยครับ

    ตั้งหัวข้อ by Arm 16/02/14, 09:38 pm

    [You must be registered and logged in to see this link.]

    UDF ข้างบนต้องใช้ MySQL ODBC 3.51 ร่วมด้วย Download here: [You must be registered and logged in to see this link.]

    แต่ตัวนี้ไม่ต้องใช้ em233 
    [You must be registered and logged in to see this link.]

    Example:
    Code:
    #include "EzMySql.au3"
    #include <Array.au3>

    If Not _EzMySql_Startup() Then
        MsgBox(0, "Error Starting MySql", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg())
        Exit
    EndIf

    $Pass = "Your password here"

    If Not _EzMySql_Open("", "root", $Pass, "", "3306") Then
        MsgBox(0, "Error opening Database", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg())
        Exit
    EndIf

    If Not _EzMySql_Exec("CREATE DATABASE IF NOT EXISTS EzMySqlTest") Then
        MsgBox(0, "Error opening Database", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg())
        Exit
    EndIf

    If Not _EzMySql_SelectDB("EzMySqlTest") Then
        MsgBox(0, "Error setting Database to use", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg())
        Exit
    EndIf

    $sMySqlStatement = "CREATE TABLE IF NOT EXISTS TestTable (" & _
                      "RowID INT NOT NULL AUTO_INCREMENT," & _
                      "Name TEXT NOT NULL ," & _
                      "Age INT NOT NULL ," & _
                      "EyeColour TEXT NOT NULL ," & _
                      "HairColour TEXT NOT NULL ," & _
                      "PRIMARY KEY (`RowID`) ," & _
                      "UNIQUE INDEX RowID_UNIQUE (`RowID` ASC) );"

    If Not _EzMySql_Exec($sMySqlStatement) Then
        MsgBox(0, "Error Creating Database Table", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg())
        Exit
    EndIf

    Local $aEyeColours[7] = ["Amber","Blue","Brown","Grey","Green","Hazel","Red"]
    Local $aHairColours[6] = ["Brown","Black","Blond","Grey","Green","Pink"]

    Local $sMySqlStatement = ""
    For $i = 1 To 50 Step 1
        $sMySqlStatement &= "INSERT INTO TestTable (Name,Age,EyeColour,HairColour) VALUES (" & _
                            "'Person" & $i & "'," & _
                            "'" & Random(1, 100, 1) & "'," & _
                            "'" & $aEyeColours[Random(0, 6, 1)] & "'," & _
                            "'" & $aHairColours[Random(0, 5, 1)] & "');"
    Next

    If Not _EzMySql_Exec($sMySqlStatement) Then
        MsgBox(0, "Error inserting data to Table", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg())
        Exit
    EndIf

    MsgBox(0, "Last AUTO_INCREMENT columnID2", _EzMySql_InsertID())

    $aOk = _EzMySql_GetTable2d("SELECT Name,EyeColour FROM TestTable WHERE EyeColour = '"& $aEyeColours[Random(0, 6, 1)] & "';")
    $error = @error
    If Not IsArray($aOk) Then MsgBox(0, $sMySqlStatement & " error", $error)
    _ArrayDisplay($aOk, "2d Array Names of certain eyecolour")

    MsgBox(0, "", "Following is how to get a row at a time of a query as a 1d array")
    If Not _EzMYSql_Query("SELECT * FROM TestTable WHERE HairColour = '"& $aHairColours[Random(0, 5, 1)] & "' LIMIT 5;") Then
    MsgBox(0, "Query Error", "Error: "& @error & @CR & "Error string: " & _EzMySql_ErrMsg())
        Exit
    EndIf

    For $i = 1 To _EzMySql_Rows() Step 1
        $a1Row = _EzMySql_FetchData()
        _ArrayDisplay($a1Row, "Result: " & $i)
    Next

    _EzMySql_Exec("DROP TABLE TestTable")

    _EzMySql_Close()
    _EzMySql_ShutDown()
    Exit
    avatar
    chaodroger
    PSsix Member Class II
    PSsix Member Class II


    รบกวน ช่วยดู สคริปผมหน่อยครับ Empty รบกวน ช่วยดู สคริปผมหน่อยครับ Empty
    จำนวนข้อความ : 30
    ความนิยม : 0
    เข้าร่วมเมื่อ : 30/12/2013

    รบกวน ช่วยดู สคริปผมหน่อยครับ Empty Re: รบกวน ช่วยดู สคริปผมหน่อยครับ

    ตั้งหัวข้อ by chaodroger 16/02/14, 11:45 pm

    ขอบคุณครับ + แล้วน้า ><"

      เวลาขณะนี้ 29/03/24, 08:09 am