Sign in to follow this  
Followers 0
Besn

mysql problem

4 posts in this topic

Hello, I cant find anything wrong in my code, i got no errors at all but it doesnt work (record is not added). I need your help.

The code.

Func _MySQLConnect($sUsername, $sPassword, $sDatabase, $sServer, $sDriver = "{MySQL ODBC 3.51 Driver}", $iPort=2083)
    Local $v = StringMid($sDriver, 2, StringLen($sDriver) - 2)
    Local $key = "HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers", $val = RegRead($key, $v)
    If @error or $val = "" Then
        SetError(2)
        Return 0
    EndIf
    $ObjConn = ObjCreate("ADODB.Connection")
    $Objconn.open ("DRIVER=" & $sDriver & ";SERVER=" & $sServer & ";DATABASE=" & $sDatabase & ";UID=" & $sUsername & ";PWD=" & $sPassword & ";PORT="&$iPort)
    If @error Then
        SetError(1)
        Return 0
    Else
        Return $ObjConn
    EndIf
EndFunc

Func _Query($oConnectionObj, $sQuery)
    If IsObj($oConnectionObj) Then
        Return $oConnectionobj.execute ($sQuery)
    EndIf
    If @error Then
        SetError(1)
        Return 0
    EndIf
    
EndFunc

Func _MySQLEnd($oConnectionObj)
    If IsObj($oConnectionObj) Then
        $oConnectionObj.close
        Return 1
    Else
        SetError(1)
        Return 0
    EndIf
EndFunc

$sql = "_MySQLConnect('uname','pw','db','server.com')"
$add = _Query($sql, "INSERT INTO 'db'.'table' ('row') VALUES ('value')")
_MySQLEnd($sql)

..and so, I got ">Exit code: 0 Time: 0.113" but it doesnt work.

I added permisions to my own IP in mysql cfg and tested query via phpmyadmin (on localhost). Ideas?:mellow:

Share this post


Link to post
Share on other sites



This does not call your connection function because it is wrapped in double quotes:

$sql = "_MySQLConnect('uname','pw','db','server.com')"

:mellow:


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

Share this post


Link to post
Share on other sites

This does not call your connection function because it is wrapped in double quotes:

$sql = "_MySQLConnect('uname','pw','db','server.com')"

:mellow:

actually it has to be in double quotes, without it, it doesnt transfer variables:

$Objconn.open ("DRIVER=" & $sDriver & ";SERVER=" & $sServer & ";DATABASE=" & $sDatabase & ";UID=" & $sUsername & ";PWD=" & $sPassword & ";PORT="&$iPort)

$Objconn.open ("DRIVER=" & $sDriver & ";SERVER=" & $sServer & ";DATABASE=" & $sDatabase & ";UID=" & $sUsername & ";PWD=" & $sPassword & ";PORT="&$iPort)^ ERROR

Share this post


Link to post
Share on other sites

Say what? :)

Let's try this again. Your script does the following:

1. Set $sql to a string, which might as well be "Hello World", because _MySQLConnect() does not get called.

2. Call the _Query() function with the string in $sql as the first parameter.

3. Now the _Query() function expects a connection object for the first parameter, but it gets a string instead.

4. The _Query() function does IsObj() on the parameter, but it's not an object, it's a string.

5. There is no ELSE condition for the IsObj() test, so no error is reported.

:mellow:


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

Share this post


Link to post
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
Sign in to follow this  
Followers 0