Jump to content

MySql query from .txt lines


tomc
 Share

Recommended Posts

Hi

I have a lot of .txt files which contain student's results. Lines 2 & 3 are their name and birth. I'd like to move these .txt to new folders respect to the class number. class number, name, and birth are in a sql table.

I tried to use the MySQL UDF an did:

#include "FileListToArrayEx.au3"
#include "array.au3"
#include "mysql.au3"

While 1
$results = _FileListToArrayEx(@ScriptDir,'*.txt',1,'',True)
    If NOT @error Then
        For $i = 1 to $results[0]
            
$sql = _MySQLConnect("root","xxxxxxxxxx","tbds","localhost")

$f = FileOpen( $results[$i], 0 )
$name_f = FileReadLine( $f , 2 )
$birth_f = FileReadLine( $f , 3 )

$classnumb = _Query($sql,"SELECT classnumb FROM students WHERE name = " & $name_f & " AND birth = " & $birth_f )
FileClose($f)
_MySQLEnd($sql)
FileMove(@ScriptDir & "\" & $results[$i], "C:\" & $classnumb, 8)
        Next
    EndIf
WEnd

this returns no error but does nothing....

Could you tell what I'm doing wrong?

Thanks!

Link to comment
Share on other sites

Hi

I have a lot of .txt files which contain student's results. Lines 2 & 3 are their name and birth. I'd like to move these .txt to new folders respect to the class number. class number, name, and birth are in a sql table.

I tried to use the MySQL UDF an did:

#include "FileListToArrayEx.au3"
#include "array.au3"
#include "mysql.au3"

While 1
$results = _FileListToArrayEx(@ScriptDir,'*.txt',1,'',True)
    If NOT @error Then
        For $i = 1 to $results[0]
            
$sql = _MySQLConnect("root","xxxxxxxxxx","tbds","localhost")

$f = FileOpen( $results[$i], 0 )
$name_f = FileReadLine( $f , 2 )
$birth_f = FileReadLine( $f , 3 )

$classnumb = _Query($sql,"SELECT classnumb FROM students WHERE name = " & $name_f & " AND birth = " & $birth_f )
FileClose($f)
_MySQLEnd($sql)
FileMove(@ScriptDir & "\" & $results[$i], "C:\" & $classnumb, 8)
        Next
    EndIf
WEnd

this returns no error but does nothing....

Could you tell what I'm doing wrong?

Thanks!

You say it returns no error, but the only place you check @error is after _FileListToArrayEx().

How do you know $sql is a valid connection?

How do you know $classnumb contains a valid query result?

Also, what breaks you out of the While/WEnd loop?

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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