午夜国产狂喷潮在线观看|国产AⅤ精品一区二区久久|中文字幕AV中文字幕|国产看片高清在线

    在mysql數(shù)據(jù)庫(kù)插入中文及中文查詢實(shí)例教程
    來(lái)源:易賢網(wǎng) 閱讀:1294 次 日期:2015-12-10 11:53:38
    溫馨提示:易賢網(wǎng)小編為您整理了“在mysql數(shù)據(jù)庫(kù)插入中文及中文查詢實(shí)例教程”,方便廣大網(wǎng)友查閱!

    //我修改之,能正常運(yùn)行,測(cè)試環(huán)境為mysql5.0,xp

    //關(guān)鍵是設(shè)置對(duì)字符集,設(shè)置gbk,gb2312測(cè)試通過(guò),utf8測(cè)試未通過(guò)

    //在運(yùn)行程序前先建立數(shù)據(jù)庫(kù)jj,注意下面幾個(gè)參數(shù)(修改為你自己的)

    // char *host = "localhost";

    // char *user = "root";

    // char *pass = "674800";

    // char *db = "jj";

    #include <windows.h>

    #include <iostream>

    #include <mysql.h>

    #include <stdio.h>

    #include <string.h>

    using namespace std;

    #pragma comment(lib,"libmysql.lib")

    int connDB();

    int create_table();

    int insert_table();

    int select_table();

    int disconnDB();

    MYSQL *mysql;

    MYSQL_RES *res;

    MYSQL_FIELD * fd;

    MYSQL_ROW row;

    char szSqlText[500]="";

    int i;

    int main()

    {

    connDB();

    // create_table();

    insert_table();

    select_table();

    disconnDB();

    return 0;

    }

    ///////////////子函數(shù)

    int connDB()//連接數(shù)據(jù)庫(kù)

    {

    char *host = "localhost";

    char *user = "root";

    char *pass = "674800";

    char *db = "jj";

    mysql = mysql_init((MYSQL*) 0);

    mysql_real_connect( mysql, host, user, pass, db,3306, NULL, 0 ) ; //鏈接到服務(wù)器

    mysql_set_character_set(mysql,"gb2312"); //設(shè)置字符集

    cout<<"conn OK!"<<endl;

    return 0;

    }

    //關(guān)閉數(shù)據(jù)庫(kù)

    int disconnDB()

    {

    mysql_close( mysql ) ;

    cout<<"disconn OK!"<<endl;

    return 0 ;

    }

    //創(chuàng)建表

    int create_table()

    {

    mysql_set_character_set(mysql,"gb2312");

    sprintf(szSqlText, \

    "create table mytable \

    (s0 varchar(100), \

    s1 char(6),\

    s2 varchar(4),\

    s3 varchar(3),s4 int)\

    ENGINE=InnoDB \

    DEFAULT CHARSET=gb2312");

    if(mysql_query( mysql, szSqlText))

    cout<<"occurred an error:"<<mysql_error(mysql)<<endl;

    return 0;

    }

    int insert_table()

    {

    mysql_set_character_set(mysql,"gb2312");

    sprintf(szSqlText,

    "insert into mytable\

    values('2000-3-10 21:01:30',\

    'Test',\

    '清風(fēng)寒劍',\

    '歲月情',\

    2500)");

    if( mysql_query( mysql, szSqlText) )

    cout<<"occurred an error:"<<mysql_error(mysql)<<endl;

    return 0;

    }

    int select_table()

    {

    mysql_set_character_set(mysql,"gb2312");

    sprintf(szSqlText, "select * from mytable ");

    if (mysql_query( mysql, szSqlText))

    {

    cout<<"occurred an error:"<<mysql_error(mysql)<<endl;

    mysql_close( mysql ) ;

    return FALSE ;

    }

    res = mysql_store_result( mysql) ;

    i = (int) mysql_num_rows( res ) ;

    cout<<"Query: "<<szSqlText<<"\n"<<i<<" records found:"<<endl;

    for ( i = 0 ; fd = mysql_fetch_field( res ) ; i++ )

    cout<<fd->name<<"\t";

    cout<<endl;

    while(row = mysql_fetch_row( res ))

    cout<<row[0]<<"\t"<<row[1]<<"\t"<<row[2]<<"\t"<<row[3]<<"\t"<<row[4]<<endl;

    mysql_free_result( res ) ;

    cout<<"select OK!"<<endl;

    return 0;

    }

    更多信息請(qǐng)查看IT技術(shù)專欄

    更多信息請(qǐng)查看數(shù)據(jù)庫(kù)
    由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

    2025國(guó)考·省考課程試聽(tīng)報(bào)名

    • 報(bào)班類型
    • 姓名
    • 手機(jī)號(hào)
    • 驗(yàn)證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn) | 投訴建議
    工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
    云南網(wǎng)警備案專用圖標(biāo)
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
    云南網(wǎng)警報(bào)警專用圖標(biāo)