MySQL Connector Go开源项目

我要开发同款
匿名用户2010年03月02日
17阅读
所属分类Google Go、数据库相关、数据库驱动程序
授权协议BSD

作品详情

MySQLConnectorGo是GoogleGo编程语言连接MySQL数据库的驱动程序。

示例代码:

packagemainimport(       "mysql";       "fmt";)//definemysqlinformationconst(       hostname       ="localhost";       username       ="gotest";       password       ="gotest";       database       ="gotest";)funcmain(){       varquerystring;       //connecttothedatabaseusingtheinformationdefinedabove       db:=mysql.Connect(hostname,username,password,database);       db.SelectDb("gotest");       //runanupdatequery       query="UPDATE`gotest`SET`testfield`='Updatesomething'";       fmt.Println("Executingquery:",query);       db.Query(query);       //ifthequerywassuccessful,viewsomeinformation       fmt.Println("Affectedrows:",db.AffectedRows,"InsertId:",db.InsertId,"\n");       //runaninsertquery       query="INSERTINTO`gotest`SET`testfield`='Insertsomething',`testfield2`=12345.123,`testfield3`=NOW()";       db.Query(query);       fmt.Println("Executingquery:",query);       //ifthequerywassuccessful,viewsomeinformation       fmt.Println("Affectedrows:",db.AffectedRows,"InsertId:",db.InsertId,"\n");       query="SELECT*FROM`gotest`";       db.Query(query);       fmt.Println("Executingquery:",query);       fmt.Println("Numrows:",db.NumRows());       for{               row:=db.FetchRow();               ifrow==nil{                       break               }               fmt.Printf("(%T)%d=>(%T)%s,(%T)%f,(%T)%+v\n",row[0],row[0],row[1],row[1],row[2],row[2],row[3],row[3]);       }       //closetheconnection       db.Close();}

查看全文
声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论