MySQL和ASP語言在Web開發中都是非常常用的語言和數據庫。在ASP中使用MySQL需要通過連接數據庫、增刪改查等操作來實現對MySQL的操作。下面是一些MySQL ASP語法的示例。
'連接數據庫 Dim conn Set conn = Server.CreateObject("ADODB.Connection") conn.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost; DATABASE=test; UID=root; PWD=123456" conn.Open '插入數據 Dim sql_insert sql_insert = "INSERT INTO users (username,password) VALUES('test','123456')" conn.Execute(sql_insert) '查詢數據 Dim sql_select sql_select = "SELECT * FROM users" Set rs = conn.Execute(sql_select) Do While Not rs.EOF Response.Write rs("username") & " - " & rs("password") & "
" rs.MoveNext Loop '更新數據 Dim sql_update sql_update = "UPDATE users SET password='654321' WHERE username='test'" conn.Execute(sql_update) '刪除數據 Dim sql_delete sql_delete = "DELETE FROM users WHERE username='test'" conn.Execute(sql_delete) '斷開連接 conn.Close Set conn = Nothing
以上代碼簡單地演示了如何連接MySQL數據庫、插入數據、查詢數據、更新數據和刪除數據。在實際開發中,還需要通過SQL語句來實現更復雜的操作。