theguy0000 Posted August 30, 2005 Share Posted August 30, 2005 i need a program that will do the basic things with an sql database, and put it into functions with easy arguments. im looking for something that i can just do this #include <sql.au3> $host = 'localhost' $username = 'username' $password = password $conn = _SQLConnect ( $host, $username, $password ) $query = _SQLPerform ( $conn, "INSERT INTO `table` VALUES `value1`" ) $close = _SQLClose ( $conn ) just something kid of like that. thanks! The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN Link to comment Share on other sites More sharing options...
AutoChris Posted August 30, 2005 Share Posted August 30, 2005 (edited) Do you mean something like this?Func SQL_Connect () Local $adCN $adCN = ObjCreate ("ADODB.Connection") ; Create SQL connection $adCN.Open ("DRIVER={SQL Server};SERVER=**SERVER**;DATABASE=**DATABASE**;uid=*****;pwd=*****;") ; Connect with required credentials $adCN.Execute ("INSERT INTO **TABLE** (**COLUMN**, **COLUMN**) VALUES ('" & $variable1 & "', '" & $variable2 & "')") $adCN.CloseEndFuncEdit: Fixxed speling misstakez Edited August 30, 2005 by SerialKiller Link to comment Share on other sites More sharing options...
theguy0000 Posted August 30, 2005 Author Share Posted August 30, 2005 i ... think so lol could you please explain all that to me? The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN Link to comment Share on other sites More sharing options...
AutoChris Posted August 30, 2005 Share Posted August 30, 2005 Func SQL_Connect () ;<==Function name Local $adCN ;<==Declare variable $adCN = ObjCreate ("ADODB.Connection") ;<==Create SQL connection $adCN.Open ("DRIVER={SQL Server};SERVER=**SERVER**;DATABASE=**DATABASE**;uid=*****;pwd=*****;") ;<==Connect with required credentials $adCN.Execute ("INSERT INTO **TABLE** (**COLUMN**, **COLUMN**) VALUES ('" & $variable1 & "', '" & $variable2 & "')") ;<==Insert data into database/tables $adCN.Close ;==>Close the database EndFunc ;==> End the SQL_Connect () Function I actually "borrowed" this script from another user and modified it for my own use. I wish I could remember who wrote it, but I believe it was scriptkitty. Link to comment Share on other sites More sharing options...
theguy0000 Posted August 30, 2005 Author Share Posted August 30, 2005 perfect, thanks! untested, lol, but at least i understand it The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN Link to comment Share on other sites More sharing options...
theguy0000 Posted August 30, 2005 Author Share Posted August 30, 2005 how do i check for error? The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN Link to comment Share on other sites More sharing options...
AutoChris Posted August 30, 2005 Share Posted August 30, 2005 how do i check for error?<{POST_SNAPBACK}>If it doesn't write to the table, you've got an error. If it writes to the table, you've got a good script. At least, that's how I do it (with this particular code). Link to comment Share on other sites More sharing options...
theguy0000 Posted August 30, 2005 Author Share Posted August 30, 2005 but does it return 0 or set @error to 1 or something like that? The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN Link to comment Share on other sites More sharing options...
AutoChris Posted August 30, 2005 Share Posted August 30, 2005 but does it return 0 or set @error to 1 or something like that?<{POST_SNAPBACK}>From the help file for ObjCreate():Success: Returns an objectFailure: Returns 0 and sets @error to 1 Other than ObjCreate(), I do not know how you could test for errors in the script. I am not familiar enough with COM Objects to be more help to you other than showing you a script I snatched off the site. Link to comment Share on other sites More sharing options...
theguy0000 Posted August 30, 2005 Author Share Posted August 30, 2005 i came up with this script, tell me if im missing anything or there are any errors... Func _SQLConnect($server, $db, $username, $password) Global $adCN;<==Declare variable $adCN = ObjCreate ("ADODB.Connection");<==Create SQL connection $adCN.Open ("DRIVER={SQL Server};SERVER=" & $server & ";DATABASE=" & $db & ";uid=" & $username & ";pwd=" & $password & ";");<==Connect with required credentials EndFunc Func _SQLClose () $adCN.Close;==>Close the database EndFunc Func _SQLExecute( $query ) $adCN.Execute ( $query ) EndFunc The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN Link to comment Share on other sites More sharing options...
AutoChris Posted August 31, 2005 Share Posted August 31, 2005 (edited) i came up with this script, tell me if im missing anything or there are any errors...Func _SQLConnect($server, $db, $username, $password) Global $adCN;<==Declare variable $adCN = ObjCreate ("ADODB.Connection");<==Create SQL connection $adCN.Open ("DRIVER={SQL Server};SERVER=" & $server & ";DATABASE=" & $db & ";uid=" & $username & ";pwd=" & $password & ";");<==Connect with required credentials EndFunc Func _SQLClose () $adCN.Close;==>Close the database EndFunc Func _SQLExecute( $query ) $adCN.Execute ( $query ) EndFunc<{POST_SNAPBACK}>Your script looks good. I played with it and was able to insert some data into one of my databases.Edit: I couldn't get it to work and realized it was user error (had a field that didn't allow NULLs and did not put anything in there) Edited August 31, 2005 by SerialKiller Link to comment Share on other sites More sharing options...
theguy0000 Posted August 31, 2005 Author Share Posted August 31, 2005 heh cool im glad it works. i kept trying tp "play with it" and no success lol anyway, thanks so much for the help! The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN 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