代码之家  ›  专栏  ›  技术社区  ›  Moretti

在C#mysql中读取mediumblob

  •  0
  • Moretti  · 技术社区  · 6 年前

    我希望从mysql数据库中读取一个blob文件,并显示blob的“哈希”段。

    这是我尝试过的。

    MySqlConnection _connection = new MySqlConnection("Database=forum;Data Source=localhost;User Id=root;Password=");
            MySqlCommand cmd = new MySqlCommand("SELECT data FROM xf_user_authenticate WHERE user_id=1", _connection);
    
            _connection.Open();
    
            MemoryStream ms = new MemoryStream();
            FileStream fs;
            Byte[] bindata;
    
            bindata = (byte[])(cmd.ExecuteScalar());
    
            ms.Write(bindata, 0, bindata.Length);
    
            API.consoleOutput($"{bindata.Length} - {bindata.ToString()}");
    

    这将输出到控制台,结果是

    97 - 58
    

    但这是我的blob的内容

    a:1:{s:4:"hash";s:60:"$2y$10$myhashishere";}
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   Steve    6 年前

    您的数据是ascii编码的字节数组,您可以使用

    ASCIIEncoding.ASCII.GetChars(bindata)