mysql_init initializes the database link – gets a link mysql_real_connect connects to the database server and executes the mysql_query query – the query statement is a string that retrieves each row separately mysql_store_result – the results are stored in the link and are a one-time query. Get the table header from the result set Information – mysql_fetch_fields – header information is stored in the memory space pointed to by the MYSQL_FIELD type pointer. Parse the header – mysql_field_count to obtain the number of columns. The for loop parses column by column. mysql_fetch_row obtains data row by row from the result set and releases memory after parsing each column for each row. Space
Close link
Specific code
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <dlfcn.h> #include <mysql/mysql.h> int main() { int ret = 0; int i = 0; MYSQL mysql; MYSQL *con = NULL; unsigned int fieldnum; printf("hello....\n"); con = mysql_init(&mysql); if (con == NULL) { ret = mysql_errno(&mysql); printf("func mysql_init() err :%d\n", ret); return ret; } con = mysql_real_connect(&mysql, "localhost", "root", "123456", "mydb2", 0, NULL, 0 ); if (con == NULL) { ret = mysql_errno(&mysql); printf("func mysql_real_connect() err :%d\n", ret); return ret; } else { printf("func mysql_real_connect() ok\n"); } //执行sql查询 mysql_query(&mysql, "set names utf8");//解决中文乱码 char *sql = "select *from employee"; ret = mysql_query(&mysql, sql); if (ret != 0) { ret = mysql_errno(&mysql); printf("func mysql_query() err :%d\n", ret); return ret; } /* //获取结果集 一次性获取 MYSQL_RES * sqlres =mysql_store_result( &mysql); if (sqlres == NULL) { ret = mysql_errno(&mysql); printf("func mysql_store_result() err :%d\n", ret); return ret; } */ //对每一行分别进行检索 MYSQL_RES * sqlres =mysql_store_result(&mysql); if (sqlres == NULL) { ret = mysql_errno(&mysql); printf("func mysql_store_result() err :%d\n", ret); return ret; } //从结果集,获取表头信息 MYSQL_FIELD *fields = mysql_fetch_fields(sqlres); fieldnum = mysql_field_count(&mysql); for (i=0; i<fieldnum; i++) { printf("%s\t", fields[i].name); } printf("\n"); //从结果集, 按照行获取信息信息 MYSQL_ROW row = NULL; //(char **) //从结果集中一行一行的获取数据 while ( row = mysql_fetch_row(sqlres)) { fieldnum = mysql_field_count(&mysql); //优化,我的行有多少列。。。。查找这样的api函数 for (i=0; i<fieldnum; i++) //经过测试 发现 不是以0结尾的指针数组。。 { printf("%s\t", row[i]); } printf("\n"); } mysql_free_result(sqlres); mysql_close(&mysql); return ret; }
The above is the content of simple data query for getting started with MySQL. For more related content, please pay attention to the PHP Chinese website (www.php.cn )!

TograntpermissionstonewMySQLusers,followthesesteps:1)AccessMySQLasauserwithsufficientprivileges,2)CreateanewuserwiththeCREATEUSERcommand,3)UsetheGRANTcommandtospecifypermissionslikeSELECT,INSERT,UPDATE,orALLPRIVILEGESonspecificdatabasesortables,and4)

ToaddusersinMySQLeffectivelyandsecurely,followthesesteps:1)UsetheCREATEUSERstatementtoaddanewuser,specifyingthehostandastrongpassword.2)GrantnecessaryprivilegesusingtheGRANTstatement,adheringtotheprincipleofleastprivilege.3)Implementsecuritymeasuresl

ToaddanewuserwithcomplexpermissionsinMySQL,followthesesteps:1)CreatetheuserwithCREATEUSER'newuser'@'localhost'IDENTIFIEDBY'password';.2)Grantreadaccesstoalltablesin'mydatabase'withGRANTSELECTONmydatabase.TO'newuser'@'localhost';.3)Grantwriteaccessto'

The string data types in MySQL include CHAR, VARCHAR, BINARY, VARBINARY, BLOB, and TEXT. The collations determine the comparison and sorting of strings. 1.CHAR is suitable for fixed-length strings, VARCHAR is suitable for variable-length strings. 2.BINARY and VARBINARY are used for binary data, and BLOB and TEXT are used for large object data. 3. Sorting rules such as utf8mb4_unicode_ci ignores upper and lower case and is suitable for user names; utf8mb4_bin is case sensitive and is suitable for fields that require precise comparison.

The best MySQLVARCHAR column length selection should be based on data analysis, consider future growth, evaluate performance impacts, and character set requirements. 1) Analyze the data to determine typical lengths; 2) Reserve future expansion space; 3) Pay attention to the impact of large lengths on performance; 4) Consider the impact of character sets on storage. Through these steps, the efficiency and scalability of the database can be optimized.

MySQLBLOBshavelimits:TINYBLOB(255bytes),BLOB(65,535bytes),MEDIUMBLOB(16,777,215bytes),andLONGBLOB(4,294,967,295bytes).TouseBLOBseffectively:1)ConsiderperformanceimpactsandstorelargeBLOBsexternally;2)Managebackupsandreplicationcarefully;3)Usepathsinst

The best tools and technologies for automating the creation of users in MySQL include: 1. MySQLWorkbench, suitable for small to medium-sized environments, easy to use but high resource consumption; 2. Ansible, suitable for multi-server environments, simple but steep learning curve; 3. Custom Python scripts, flexible but need to ensure script security; 4. Puppet and Chef, suitable for large-scale environments, complex but scalable. Scale, learning curve and integration needs should be considered when choosing.

Yes,youcansearchinsideaBLOBinMySQLusingspecifictechniques.1)ConverttheBLOBtoaUTF-8stringwithCONVERTfunctionandsearchusingLIKE.2)ForcompressedBLOBs,useUNCOMPRESSbeforeconversion.3)Considerperformanceimpactsanddataencoding.4)Forcomplexdata,externalproc


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SublimeText3 Chinese version
Chinese version, very easy to use

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver Mac version
Visual web development tools
