diff --git a/testMySQL.sln b/testMySQL.sln new file mode 100644 index 0000000000000000000000000000000000000000..eba55cfe6b66bcfd7d1f0ccb7f07d57653495f63 --- /dev/null +++ b/testMySQL.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29519.181 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testMySQL", "testMySQL\testMySQL.vcxproj", "{B9F757C9-6AB0-4D8C-8B42-1C0370031074}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B9F757C9-6AB0-4D8C-8B42-1C0370031074}.Debug|x64.ActiveCfg = Debug|x64 + {B9F757C9-6AB0-4D8C-8B42-1C0370031074}.Debug|x64.Build.0 = Debug|x64 + {B9F757C9-6AB0-4D8C-8B42-1C0370031074}.Debug|x86.ActiveCfg = Debug|Win32 + {B9F757C9-6AB0-4D8C-8B42-1C0370031074}.Debug|x86.Build.0 = Debug|Win32 + {B9F757C9-6AB0-4D8C-8B42-1C0370031074}.Release|x64.ActiveCfg = Release|x64 + {B9F757C9-6AB0-4D8C-8B42-1C0370031074}.Release|x64.Build.0 = Release|x64 + {B9F757C9-6AB0-4D8C-8B42-1C0370031074}.Release|x86.ActiveCfg = Release|Win32 + {B9F757C9-6AB0-4D8C-8B42-1C0370031074}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {954150D6-65ED-4125-BC3C-3EF796AC260D} + EndGlobalSection +EndGlobal diff --git a/testMySQL/testMySQL.cpp b/testMySQL/testMySQL.cpp new file mode 100644 index 0000000000000000000000000000000000000000..84d34d9f216f1260ee8b28f4304d44ce23aac50b --- /dev/null +++ b/testMySQL/testMySQL.cpp @@ -0,0 +1,47 @@ +// testMySQL.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 +// +#include +#include +#include +using namespace std; + +void test() +{ + MYSQL* pConn; + pConn = mysql_init(NULL); + if (mysql_real_connect(pConn, "localhost", "root", "root19537", "test", 0, NULL, 0)) + { + cout << "成功连接MySQL数据库" << endl; + mysql_query(pConn, "set names gbk"); + + if (!mysql_query(pConn, "select * from tb_product;")) + { + MYSQL_RES* result = mysql_store_result(pConn); + MYSQL_ROW row; + while (row = mysql_fetch_row(result)) + { + cout << row[0] << " " << row[1] << endl; + } + mysql_free_result(result); + } + else + { + cout << "查询失败:" << mysql_errno(pConn) << endl; + return; + } + mysql_close(pConn); + return; + } + else + { + cout << "无法连接MySQL数据库:" << mysql_errno(pConn) << endl; + return; + } +} + +int main() +{ + test(); + return 0; +} + diff --git a/testMySQL/testMySQL.vcxproj b/testMySQL/testMySQL.vcxproj new file mode 100644 index 0000000000000000000000000000000000000000..ff0490220e4fb29ea7bfb23ce955401dfc57602c --- /dev/null +++ b/testMySQL/testMySQL.vcxproj @@ -0,0 +1,165 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + {B9F757C9-6AB0-4D8C-8B42-1C0370031074} + Win32Proj + testMySQL + 10.0 + + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + Application + true + v142 + Unicode + + + Application + false + v142 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + D:\users\lenovo\mysql-8.0.18-winx64\include;%(AdditionalIncludeDirectories) + + + Console + true + D:\users\lenovo\mysql-8.0.18-winx64\lib;%(AdditionalLibraryDirectories) + libmysql.lib;%(AdditionalDependencies) + + + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + D:\users\lenovo\mysql-8.0.18-winx64\include;%(AdditionalIncludeDirectories) + + + Console + true + + + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/testMySQL/testMySQL.vcxproj.filters b/testMySQL/testMySQL.vcxproj.filters new file mode 100644 index 0000000000000000000000000000000000000000..f4fb8023ed4280c37792f492a09871ccf735d9cd --- /dev/null +++ b/testMySQL/testMySQL.vcxproj.filters @@ -0,0 +1,35 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {88b64db4-959e-436d-974e-d4c0c9e8fbc2} + + + + + 源文件 + + + + + lib + + + + + lib + + + \ No newline at end of file