利用JavaScript連接mysql服務器,具體方法如下:
<script language="javascript">
var conn = new ActiveXObject("ADODB.Connection"); //創建數據庫連接bai對象
var rs = new ActiveXObject("ADODB.Recordset"); //創建數據集對象
try{
var connectionstring = "Driver={mysql ODBC 5.2w Driver};Server=localhost;Database=myDataBase;User=myUsername; Password=myPassword;Option=3;Port=3306";
conn.open(connectionstring); //打開連接
var sql = " select * from tb_col "; //查詢語句
rs.open(sql,conn); //打開數據集
while(!rs.eof){ //遍歷所有記錄
rs.moveNext(); //下一條記錄
}
rs.close(); //關閉記錄集
conn.close();
//關閉數據庫連接
} catch(e){
WScript.Echo(e.message); //異常報告
} finally{
}
</script>