Besn Posted August 26, 2011 Share Posted August 26, 2011 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. expandcollapse popupFunc _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? Link to comment Share on other sites More sharing options...
PsaltyDS Posted August 27, 2011 Share Posted August 27, 2011 This does not call your connection function because it is wrapped in double quotes: $sql = "_MySQLConnect('uname','pw','db','server.com')" 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 More sharing options...
Besn Posted August 28, 2011 Author Share Posted August 28, 2011 This does not call your connection function because it is wrapped in double quotes: $sql = "_MySQLConnect('uname','pw','db','server.com')" 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 Link to comment Share on other sites More sharing options...
PsaltyDS Posted August 29, 2011 Share Posted August 29, 2011 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. 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now