#include#includeintmain(void){MYSQL_RES*result;MYSQL_ROWrow;MYSQL*connection,mysql;intstate;mysql_init(&mysql);connection=mysql_real_connect(&mysql,"localhost","root","951241","mysql",0," />

日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

ubuntu linux mysql 開發(fā)模式與連接編譯

系統(tǒng) 2008 0

【源碼 測試】

#include <sys/time.h>
#include <stdio.h>
#include <mysql.h>

int main(void)
{
??? MYSQL_RES *result;
??? MYSQL_ROW row;
??? MYSQL *connection, mysql;
??? int state;

??? mysql_init(&mysql);
??? connection = mysql_real_connect(&mysql,"localhost","root","951241","mysql",0,0,0);
??? if (connection == NULL)
??? {
??????? printf(mysql_error(&mysql));
??????? return 1;
??? }

??? state = mysql_query(connection, "SELECT Host, User, Password FROM user");
??? if (state !=0)
??? {
??????? printf(mysql_error(connection));
??????? return 1;
??? }
??? result = mysql_store_result(connection);
??? printf("Rows:%d\n",mysql_num_rows(result));

??? while ( ( row=mysql_fetch_row(result)) != NULL )
??? {
??????? printf("%s, %s, %s\n", (row[0] ? row[0] : "NULL"), (row[1] ? row[1] : "NULL" ), (row[2] ? row[2] : "NULL"));
??? }

??? mysql_free_result(result);
??? mysql_close(connection);

??? return 0;
};

【mysql】
要裝有Mysql 數(shù)據(jù)庫 apt-get install mysqlclient mysqlserver libmysqlclient-dev

【編譯】
sudo gcc $(mysql_config --cflags) main.c -o $(mysql_config --libs)
sudo g++ test.cpp -I/usr/include/mysql /usr/lib/mysql/libmysqlclient??? -----------------[這個沒上面那個好用,有可能目錄不對]

?

【部分錯誤分析1】
/home/qiang/client_soft/mysql/main.c||In function ‘main’:|
/home/qiang/client_soft/mysql/main.c|13|error: stray ‘\342’ in program|
/home/qiang/client_soft/mysql/main.c|13|error: stray ‘\200’ in program|
………………………………………………………………………………………………
finished: 10 errors, 5 warnings ===|

這個'342'是雙引號為漢字,由于是從網(wǎng)上down的,符號問題。。。。常常出現(xiàn)

【部分錯誤分析2】

包含文件不會。只要安裝好mysql和程序沒有問題,運(yùn)行上邊編譯的命令(如果是IDE要手動加載),就不有問題。

【運(yùn)行效果】數(shù)據(jù)庫 mysql.user 存在數(shù)據(jù)才有顯示 可以更改 上面的代碼

ubuntu linux mysql 開發(fā)模式與連接編譯

ubuntu linux mysql 開發(fā)模式與連接編譯


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 横峰县| 中卫市| 宁阳县| 凯里市| 新田县| 玉山县| 萨嘎县| 九江市| 丹江口市| 台山市| 大新县| 潞西市| 大邑县| 肇庆市| 临海市| 玉门市| 京山县| 清徐县| 汉阴县| 宁海县| 普宁市| 萝北县| 义乌市| 岳阳县| 巴楚县| 抚松县| 越西县| 罗城| 曲麻莱县| 台南县| 门源| 红河县| 陆良县| 田东县| 长葛市| 漳浦县| 神池县| 琼中| 新津县| 永康市| 酒泉市|