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