mysql connect c++
ÏÈÇ°ÔÚ²âÊÔmysql connect c++½Ó¿ÚµÄʱºòÔËÐÐÆä¹Ù·½ÌṩµÄÀý×Ó
21.5.5.6. MySQL Connector/C++ Complete Example 2
The following code shows a complete example of how to use MySQL Connector/C++:
/* Copyright 2008 Sun Microsystems, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
There are special exceptions to the terms and conditions of the GPL
as it is applied to this software. View the full text of the
exception in file EXCEPTIONS-CONNECTOR-C++ in the directory of this
software distribution.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* Standard C++ includes */
#include <stdlib.h>
#include <iostream>
/*
Include directly the different
headers from cppconn/ and mysql_driver.h + mysql_util.h
(and mysql_connection.h). This will reduce your build time!
*/
#include "mysql_connection.h"
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
#include <cppconn/prepared_statement.h>
using namespace std;
int main(void)
{
cout << endl;
cout << "Let's have MySQL count from 10 to 1..." << endl;
try {
sql::Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
sql::ResultSet *res;
sql::PreparedStatement *pstmt;
/* Create a connection */
driver = get_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "root", "root");
/* Connect to the
Ïà¹ØÎĵµ£º
×òÌ죬¹«Ë¾´Ó·þÎñÆ÷ÉϸãÏÂÀ´Ò»¸ö´óµÄÊý¾Ý¿â£¬Îļþ´óСΪ487MB£¬ÓÐͬÊÂ˵½«php.iniµÄÎļþÅäÖÃÖеÄpost_max_size¸ÄΪ±ÈÄãÒªµ¼ÈëµÄÊý¾Ý¿âÎļþ´óһЩµÄ£¬±ÈÈçÏÖÔÚÎÒÒªµÄµ¼ÈëµÄÊý¾Ý¿âÎļþÊÇ487MB£¬ÄÇô¿ÉÒÔ½«´ËÏî¸ü¸ÄΪ£º700MB£¬ÔÙʹÓÃphpMyAdmin¹¤¾ßµÄµ¼È빦ÄÜÀ´ÊµÏÖ£¬µ«ÊÇ£¬ÎÒÊÔÓÃÁË´ËÖÖ·½·¨²»ÄÜ×àЧ£¬È»ºóÓëÓоÑéµÄÅóÓѽ»Á÷£ ......
ÕâÀïÊÇʹÓÃODBCÀ´×ª»»Êý¾Ý¿âµÄ¡£
1.°²×°mysqlÊý¾Ý¿âµÄODBCÇý¶¯£¬mysql¹ÙÍøÓÐÏÂÔØhttp://dev.mysql.com/downloads/connector/odbc/
2.´ò¿ª¿ØÖÆÃæ°å\¹ÜÀí¹¤¾ß\Êý¾ÝÔ´ODBC£¬ÔÚÓû§DSNÖÐÌí¼ÓÒ»¸öMySQL ODBC Êý¾ÝÔ´¡£
3.½Ó×ÅÔÚÏÂÃæµÄ´°ÌåÖÐÊäÈëÊý¾ÝÔ´Ãû³Æ£¬Èçmysqlodbc£»È»ºóÊäÈë·þÎñÆ÷ServerµØÖ·£¨localhost»òÆäËû£©£¬Óû§Us ......
MySQLÖØа²×°µÄʱºò³öÏÖÁËÎÊÌ⣺Could not start the service MySQL. Error:0,ÔÒòÊÇûÓжԾɵÄMySQLÍêȫжÔصô¡£
ÔÚÄã´ÓµçÄÔÀïжÔؾɵÄMYSQLÊý¾Ý¿â·þÎñʱ£¬Ê×ÏÈÏÈÔÚWINDOWS·þÎñÀïÍ£µôMYSQLµÄ·þÎñ¡£ÔÙµ½¿ØÖÆÃæ°åÀïµÄÔö¼Óɾ³ý³ÌÐòÄÚ½øÐÐɾ³ý£¬È»ºóÊÖ¶¯É¾³ýÔ°²×°Îļþ,µ«ÊÇÄã²¢²»ÄÜÍêÕûµÄ°ÑMYSQL·þÎñɾ ......
php£«mysqlÔúʵ¸öÈË»ù±¾¹¦
Ò». 10¾ä»°
1.²»ÒªÒÀÀµregister_global=ONµÄ»·¾³£¬´ÓÄã¸Õ¶®µÃÅäÖÃphpÔËÐл·¾³ÉõÖÁÉв»Ã÷°×register_globalµÄON/OFF»á¶Ô×Ô¼ºÓÐʲôӰÏìµÄÄÇÌìÆ𣬾ÍÓ¦¸ÃÓ¸ҵذÑËüÉèΪOFF.
2.д³ÌÐòÇ°¿´¿´ÔõôÓÃerror_reporting.
3.²»¶®¾ÍÎʱ¾Éíû´í£¬µ«ÄãÐèÒªÔÚÄÇ֮ǰ²é²éÊֲᡣ
4.µ±È»£¬ÄãÐèÒª¶®µÃʹÓÃÊÖ ......
ʹÓÃÁÙʱ±íµÄºÃ´¦£º
ʹÓÃÁÙʱ±í´æ·ÅÖмä½á¹û,¼ÓËÙ²éѯ£¬»ò´æ·ÅÁÙʱ½á¹û.
(1)
´´½¨ÁÙʱ±íºÜÈÝÒ×£¬¸øÕý³£µÄCREATE TABLEÓï¾ä¼ÓÉÏTEMPORARY¹Ø¼ü×Ö£º
CREATE TEMPORARY TABLE tmp_table (
name VARCHAR(10) NOT NULL,
value INTEGER NOT NULL
)
(2)
ÁÙʱ±í½«ÔÚÄãÁ¬½ÓMySQLÆÚ¼ä´æÔÚ¡£µ±Äã¶Ï¿ªÊ±£¬MySQL ......