Jump to content

script request


Recommended Posts

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

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.Close

EndFunc

Edit: Fixxed speling misstakez

Edited by SerialKiller
Link to comment
Share on other sites

Func SQL_Connect () ;<==Function name :whistle:

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

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 object

Failure: 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. :whistle:

Link to comment
Share on other sites

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

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 by SerialKiller
Link to comment
Share on other sites

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

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...