本文整理汇总了C++中MySQL类的典型用法代码示例。如果您正苦于以下问题:C++ MySQL类的具体用法?C++ MySQL怎么用?C++ MySQL使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MySQL类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: f_mysql_async_query_result
Variant f_mysql_async_query_result(CVarRef link_identifier) {
MySQL* mySQL = MySQL::Get(link_identifier);
if (!mySQL) {
raise_warning("supplied argument is not a valid MySQL-Link resource");
return Variant(Variant::NullInit());
}
MYSQL* conn = mySQL->get();
if (!conn || (conn->async_op_status != ASYNC_OP_QUERY &&
conn->async_op_status != ASYNC_OP_UNSET)) {
raise_warning("runtime/ext_mysql: attempt to check query result when query "
"not executing");
return Variant(Variant::NullInit());
}
int error = 0;
auto status = mysql_real_query_nonblocking(
conn, mySQL->m_async_query.data(), mySQL->m_async_query.size(), &error);
if (status != NET_ASYNC_COMPLETE) {
return Variant(Variant::NullInit());
}
if (error) {
return Variant(Variant::NullInit());
}
mySQL->m_async_query.reset();
MYSQL_RES* mysql_result = mysql_use_result(conn);
MySQLResult *r = NEWOBJ(MySQLResult)(mysql_result);
r->setAsyncConnection(mySQL);
Resource ret(r);
return ret;
}
示例2: Get
bool MySQL::CloseConn(const Variant& link_identifier) {
MySQL *mySQL = Get(link_identifier);
if (mySQL && !mySQL->isPersistent()) {
mySQL->close();
}
return true;
}
示例3: main
int main ( ) {
/* Create MySQL object */
MySQL sql;
/* Open Database */
std::cout << "Connecting to 'localhost' using 'test' database" << std::endl;
assert ( sql.connect ( "localhost", "root", "blue23", "test" ) == true );
std::cout << "Opening was successful" << std::endl;
/* Create a table */
std::cout << "Creating table tbl1 (one int, two int)" << std::endl;
assert ( sql.exec ( "create table tbl1 (one int, two int);" ) == 1 );
std::cout << "Created table tbl1" << std::endl;
/* Insert values */
std::cout << "Insert values ( 10, 10 ) into tbl1" << std::endl;
assert ( sql.exec ( "insert into tbl1 (one, two) VALUES ( 10, 10 )" ) == 1 );
std::cout << "Inserted values successfully" << std::endl;
/* Query values */
std::cout << "Query values to make sure of integraty" << std::endl;
assert ( sql.query ( "select * from tbl1" ) == 1);
std::cout << "Query was successful" << std::endl;
/* Integraty of values */
std::cout << "Checking to see if query returned results" << std::endl;
assert ( sql.hasNext ( ) );
std::cout << "Results were returned" << std::endl;
/* Check to see that we get a total of two columns ( one, two ) from query */
std::cout << "Checking to see if a record has two entries ( one, two )" << std::endl;
std::vector<std::string> l = sql.next ( );
assert( l.size() == 2 );
std::cout << "Integraty was achieved for record count" << std::endl;
/* Check Integraty of inserted row ( 10, 10 ) */
std::cout << "Checking to see one = 10" << std::endl;
assert( l[0].compare ( "10" ) == 0 );
std::cout << "Checking to see two = 10" << std::endl;
assert( l[1].compare ( "10" ) == 0 );
/* Clear out values */
std::cout << "Clearing values from database" << std::endl;
assert ( sql.query ( "delete from tbl1" ) == 1 );
std::cout << "Database values were cleared" << std::endl;
/* Remove table */
std::cout << "Removing table tbl1 from database" << std::endl;
assert ( sql.query ( "DROP TABLE IF EXISTS tbl1" ) == 1);
std::cout << "Table tbl1 was removed from database" << std::endl;
/* Close database */
std::cout << "Database attempting to close" << std::endl;
sql.disconnect ();
std::cout << "Database closed" << std::endl;
/* Closing statements */
std::cout << "Finished unit testing :D" << std::endl;
return 1;
};
示例4: f_mysql_async_status
int64_t f_mysql_async_status(CVarRef link_identifier) {
MySQL *mySQL = MySQL::Get(link_identifier);
if (!mySQL || !mySQL->get()) {
raise_warning("supplied argument is not a valid MySQL-Link resource");
return -1;
}
return mySQL->get()->async_op_status;
}
示例5: HHVM_FUNCTION
static int64_t HHVM_FUNCTION(mysql_async_status,
const Variant& link_identifier) {
MySQL *mySQL = MySQL::Get(link_identifier);
if (!mySQL || !mySQL->get()) {
raise_warning("supplied argument is not a valid MySQL-Link resource");
return -1;
}
return mySQL->get()->async_op_status;
}
示例6: f_mysql_warning_count
Variant f_mysql_warning_count(CVarRef link_identifier /* = null */) {
MySQL *mySQL = MySQL::Get(link_identifier);
if (!mySQL) {
raise_warning("supplied argument is not a valid MySQL-Link resource");
return false;
}
MYSQL *conn = mySQL->get();
if (conn) {
return (int64_t)mysql_warning_count(conn);
}
return false;
}
示例7: ajaxIsEmailExist
void UserModule::ajaxIsEmailExist(WebPage *page, HttpRequest &request) {
MySQL *query = manager->newQuery();
String email = request.header.POST.getValue("email");
String sql = (String)"select id from users where (email='" + email + "')";
string sql8 = sql.to_string();
if (query->active(sql) > 0) {
page->tplIndex->out("out", "<note>\n<result>1</result></note>\n");
}
manager->deleteQuery(query);
}
示例8: MySQL
MySQL* ConnectionPool::init_connect() {
MySQL *query = new MySQL();
if (!query->init()) {
printf("!query->init()\n");
return NULL;
}
if (!query->connect("127.0.0.1", "root", "", "sitev")) {
printf("!query->connect()\n");
return NULL;
}
query->exec("SET NAMES utf8");
return query;
}
示例9: paintPageWidgets
void WidgetManager::paintPageWidgets(WebPage *page) {
if (page == NULL) return;
MySQL *query = page->site->manager->newQuery();
String sql = "select widgetId, tag from widget_site where siteId='" + (String)page->site->siteId + "'";
if (query->active(sql)) {
int count = query->getRowCount();
for (int i = 0; i < count; i++) {
int widgetId = query->getFieldValue(i, "widgetId").toInt();
String tag = query->getFieldValue(i, "tag");
paintWidget(page, tag, widgetId);
}
}
}
示例10: getModuleUrl
String WebModule::getModuleUrl() {
MySQL *query = manager->newQuery();
String sql = "select * from modules where id='" + (String)moduleId + "'";
if (query->exec(sql)) {
if (query->storeResult()) {
int count = query->getRowCount();
if (count > 0) {
String url = query->getFieldValue(0, "url");
return url;
}
}
}
return "";
}
示例11: f_mysql_errno
Variant f_mysql_errno(const Variant& link_identifier /* = null */) {
MySQL *mySQL = MySQL::Get(link_identifier);
if (!mySQL) {
raise_warning("supplied argument is not a valid MySQL-Link resource");
return false;
}
MYSQL *conn = mySQL->get();
if (conn) {
return (int64_t)mysql_errno(conn);
}
if (mySQL->m_last_error_set) {
return (int64_t)mySQL->m_last_errno;
}
return false;
}
示例12: f_mysql_error
Variant f_mysql_error(CVarRef link_identifier /* = null */) {
MySQL *mySQL = MySQL::Get(link_identifier);
if (!mySQL) {
raise_warning("supplied argument is not a valid MySQL-Link resource");
return false;
}
MYSQL *conn = mySQL->get();
if (conn) {
return String(mysql_error(conn), CopyString);
}
if (mySQL->m_last_error_set) {
return String(mySQL->m_last_error);
}
return false;
}
示例13: paint
void StaticPageModule::paint(WebPage *page, HttpRequest &request) {
MySQL *query = manager->newQuery();
String sql = "select txt.value from data d, dataText txt where d.dataId=txt.id and d.pageId='" + (String)page->pageId + "'";
printf("sql = %s\n", sql.toString8().c_str());
if (query->exec(sql)) {
if (query->storeResult()) {
int count = query->getRowCount();
if (count > 0) {
String content = query->getFieldValue(0, "value");
page->out("content", content);
}
}
}
}
示例14: ajax
void NewsModule::ajax(WebPage *page, HttpRequest &request) {
MySQL *query = manager->newQuery();
String obj = request.header.GET.getValue("p1");
String func = request.header.GET.getValue("p2");
String uuid = request.header.COOKIE.getValue("uuid");
if (obj == "post") {
if (func == "sendComment") {
String comment = request.header.POST.getValue("comment");
int newsId = request.header.POST.getValue("newsId").toInt();
int userId = manager->getUserId(uuid);
String result = "";
String sql = "insert into comments (userId, newsId, comment) values ('" + (String)userId + "', '" + (String)newsId + "', '" + comment + "')";
if (query->exec(sql)) {
result = "1";
}
page->tplIndex->out("out", "<note>\n");
page->tplIndex->out("out", "<result>" + result + "</result>\n");
page->tplIndex->out("out", "</note>\n");
}
if (func == "sendPost") {
String name = request.header.POST.getValue("name");
String text = request.header.POST.getValue("content");
text = request.header.htmlEntitiesDecode(text.toString8());
int userId = manager->getUserId(uuid);
String result = "";
String sql = "insert into dataNews (name, text) values ('" + name + "', '" + text + "')";
if (query->exec(sql)) {
sql = "insert into data (pageId, dataId, moduleId, userId) values('" + (String)page->pageId + "', LAST_INSERT_ID(), '3', '" + (String)userId + "')";
if (query->exec(sql)) {
result = "1";
}
else result = "3";
}
else result = "2";
page->tplIndex->out("out", "<note>\n");
page->tplIndex->out("out", "<result>" + result + "</result>\n");
page->tplIndex->out("out", "<sql>" + sql + "</sql>\n");
page->tplIndex->out("out", "</note>\n");
}
}
}
示例15: activate
void UserModule::activate(WebPage *page, HttpRequest &request) {
MySQL *query = manager->newQuery();
String p3 = request.header.GET.getValue("p3");
String sql = "update users set active = '1', password=newPassword where uuid = '" + p3 + "'";
WebTemplate * tpl = new WebTemplate();
String activateTpl = "";
if (query->exec(sql)) {
activateTpl = "activateSuccess_tpl.html";
}
else {
activateTpl = "activateFail_tpl.html";
}
if (tpl->open(manager->modulePath + "/user/" + activateTpl)) {
tpl->exec();
page->out("content", tpl->html);
}
manager->deleteQuery(query);
}