我不敢相信,但所有迹象都表明我的 PowerShell 代码正在返回SELECT
查找 1 条记录作为对象的查询结果,但如果有两条或更多条记录,则相同的代码返回一个对象数组。我究竟做错了什么?
下面是代码:
function Connect-MySQL([string]$MySQLHost, [string]$user, [string]$pass, [string]$database) {
Write-Verbose "Connect-MySQL"
# Load MySQL .NET Connector Objects
[void][system.reflection.Assembly]::LoadWithPartialName("MySql.Data")
# Open Connection
$connStr = "server=$MySQLHost;port=3306;uid=$user;pwd=$pass;database=$database;Pooling=FALSE"
try {
$con = New-Object MySql.Data.MySqlClient.MySqlConnection($connStr)
$con.Open()
} catch [System.Management.Automation.PSArgumentException] {
Write-Verbose "Unable to connect to MySQL server, do you have the MySQL connector installed..?"
Write-Verbose $_
Exit
} catch {
Write-Verbose "Unable to connect to MySQL server..."
Write-Verbose $_.Exception.GetType().FullName
Write-Verbose $_.Exception.Message
exit
}
Write-Verbose "Connected to MySQL database $MySQLHost\$database"
return …
Run Code Online (Sandbox Code Playgroud)