|
用au3连接数据库,我运行一下代码,没有弹出错误信息,是不是就是成功了?如何进行查询。
$db_user="postgres"
$db_password="11"
$db_name="postgres"
$db_host="localhost"
$sServer="localhost"
Func _postgresSQLConnect($sUsername, $sPassword, $sDatabase, $sServer, $sDriver = "{postgreSQL ODBC Driver(ansi)}", $iPort=5432)
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
$sql = _postgresSQLConnect($db_user,$db_password,$db_name,$db_host)
If @Error = 2 Then MsgBox(0, "Error", "请安装 ODBC Driver!")
If @Error = 1 Then MsgBox(0, "Error", "连接数据库失败!") |
|