Hello, Connector/NET(PowerShell) World!

Posted on 4月 6th, 2013 by cx20

Connector/NET(PowerShell)

Connector/NET は、.NET ベースの MySQL 接続用 API である。
以下は PowerShell による Connector/NET ライブラリを使用した MySQL への接続例となっている。

ソースコード(PowerShell + Connector/NET + MySQL)

[void][Reflection.Assembly]::LoadWithPartialName("MySql.Data")
$conStr = "server=localhost;user id=root;password=P@ssW0rd"
$sqlStr = "SELECT 'Hello, Connector/NET World!' AS Message"
$con = New-Object MySql.Data.MySqlClient.MySqlConnection($conStr)
$cmd = New-Object MySql.Data.MySqlClient.MySqlCommand($sqlStr, $con)
$con.Open()
$reader = $cmd.ExecuteReader()
while ( $reader.read() )
{
    $reader.getName(0)
    "---------------------"
    $reader[0]
}
$con.Close()

実行方法

C:¥> powershell -file Hello.ps1

実行結果

MESSAGE
---------------------
Hello, Connector/NET World!

Tags:

Categories: Connector/NET, PowerShell

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

WP-SpamFree by Pole Position Marketing