2,187
edits
m (→Test for NULL: Added additional error example) |
(→Connect: Made function names consistent) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
To be able to interact with a MySQL database from PowerShell you need to have the MySQL .NET Connector installed first - http://dev.mysql.com/downloads/connector/net/ | {{#widget:Widget:GoogleAdSenseSkyscraper}} | ||
To be able to interact with a MySQL database from PowerShell you need to have the MySQL .NET Connector installed first on the machine that you're going to run PowerShell from - http://dev.mysql.com/downloads/connector/net/ | |||
= Connect = | = Connect = | ||
Line 19: | Line 20: | ||
$conn.Close() | $conn.Close() | ||
} | } | ||
</source> | |||
So, for example... | |||
<source lang="powershell"> | |||
# Connection Variables | # Connection Variables | ||
$user = 'myuser' | $user = 'myuser' | ||
Line 34: | Line 36: | ||
Improved connect function with error catcher... | Improved connect function with error catcher... | ||
<source lang="powershell"> | <source lang="powershell"> | ||
function | function Connect-MySQL([string]$user, [string]$pass, [string]$MySQLHost, [string]$database) { | ||
# Load MySQL .NET Connector Objects | # Load MySQL .NET Connector Objects | ||
[void][system.reflection.Assembly]::LoadWithPartialName("MySql.Data") | [void][system.reflection.Assembly]::LoadWithPartialName("MySql.Data") | ||
Line 58: | Line 60: | ||
} | } | ||
</source> | </source> | ||
{{#widget:Widget:GoogleAdSenseSkyscraper}} | |||
= Commands = | = Commands = |