Advertisement
Combreal

browseTableValueSQL.ps1

Mar 2nd, 2024
1,060
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Requieres MySQL Connector NET 8.3.0 and SimplySql Powershell Module
  2.  
  3. [void][system.reflection.Assembly]::LoadFrom("C:\Program Files (x86)\MySQL\MySQL Connector NET 8.3.0\MySql.Data.dll")
  4.  
  5. $Mysqlhost= "localhost"
  6. $Mysqluser= "root"
  7. $Mysqlpass= "myrootpswd"
  8. $Mysqldatabase= "mydb"
  9.  
  10. $Connection = [MySql.Data.MySqlClient.MySqlConnection]@{ConnectionString="server=$Mysqlhost;uid=$Mysqluser;pwd=$Mysqlpass;database=$Mysqldatabase"}
  11. $Connection.Open()
  12. $sql = New-Object MySql.Data.MySqlClient.MySqlCommand
  13. $sql.Connection = $Connection
  14.  
  15. $sql.CommandText = "SELECT title FROM recipes"
  16. $myreader = $sql.ExecuteReader()
  17. while($myreader.Read()) {
  18.     $myreader.GetString(0)
  19. }
  20. $myreader.Close()
  21.  
  22. $sql.CommandText = "SELECT full_name FROM users"
  23. $myreader = $sql.ExecuteReader()
  24. while($myreader.Read()) {
  25.     $myreader.GetString(0)
  26. }
  27. $myreader.Close()
  28.  
  29. $Connection.Close()
Tags: sql powershel
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement