0

sqlwriterow 函数我发送一个查询并从我正在寻找的特定行中检索数据。我在发送包含 powershell 变量的查询时遇到问题。现在,如果我输入 26(或我正在寻找的任何 id)而不是写 '$id',我会得到预期的数据。但是,如果我输入变量,我将不会得到任何数据。并玩弄格式,例如取出我会得到的报价

您的 SQL 语法有错误;检查与您的 MariaDB 服务器版本相对应的手册,以获取在第 1 行的 '' 附近使用的正确语法

我尝试了各种格式化它的方法,例如

$sqlcmd4appcheck = "use spree; select * from tasks_profiles where id = '$id'"
$sqlcmd4appcheck = "use spree; select * from tasks_profiles where id = ``$id``"
$sqlcmd4appcheck = "use spree; select * from tasks_profiles where id = ''$id''"
$sqlcmd4appcheck = "use spree; select * from tasks_profiles where id = "$id""

代码:

function sqlwriterow($args1, $args2) {
    [void][system.reflection.Assembly]::LoadFrom(“C:\Program Files (x86)\MySQL\MySQL Connector Net 5.0.9\Binaries\.NET 2.0\MySQL.Data.dll”)
    $dbconnect = New-Object MySql.Data.MySqlClient.MySqlconnection
    $dbconnect.connectionString = "server=207.52.55.122;user id=spree;pwd=spr33Adm1n;database=spree"
    if (-not ($dbconnect.State -like "Open")) { $dbconnect.Open() }
    $sql = New-Object MySql.Data.MySqlclient.MySqlcommand
    $sql.Connection = $dbconnect
    $sql.Commandtext = $args1
    $dataset=New-Object system.Data.Dataset
    $dataAdaptor=New-Object MySql.Data.MySqlClient.MySqlDataAdapter($sql)
    $dataAdaptor.fill($dataset)
    $script:row = $dataset.tables[0].Rows[0].$args2
    $dbconnect.Close()

}


$id = 26
$sqlcmd4appcheck = "use spree; select * from tasks_profiles where id = '$id'"

sqlwriterow -args1 $sqlcmd4appcheck -args2 "app"; $app = $row
4

0 回答 0