C++连接MySQL 操作的封装

2023-05-16

以前写过一篇 c++连接mysql 的博客, 每次都要写类来封装数据库的操作函数, 参考一位大佬的封装,不说了,直接上代码:
头文件如下:

#pragma once

#include <windows.h>
#include <iostream>
#include <mysql.h>
#include <stdint.h>
#include <string>
#include <algorithm>
#include <map>
#include <iostream>
#include <sstream>

class MySQLConnection
{

public:
    MySQLConnection();
    ~MySQLConnection();
    // connects to a MySQL-server
    bool Connect(const std::string &sHostname, const uint16_t &wPort, const std::string &sUsername, const std::string &sPassword, const std::string &sDB);
    // selects a DB
    bool SelectDB(const std::string &sSchemaName);
    // disconnects (huh, who guessed this?)
    void Disconnect();
    // returns the last error string
    const std::string GetLastError() const;
    // gets a pointer to the MySQL connection
    MYSQL *getConn();
    // returns true when connected
    bool IsConnected();
    // returns an escaped string
    const std::string EscapeString(const std::string &value) const;

private:
    MYSQL *m_pMySQLConn;
    bool m_bIsConnected;
    std::string m_sHostname;
    std::string m_sUsername;
    std::string m_sPassword;
    std::string m_sSchemaName;
    uint16_t m_wPort;
};

class MySQLQuery
{
public:
    MySQLQuery(MySQLConnection *mConn, const std::string &sStatement);
    ~MySQLQuery();

    // sets the value of idx to a given string (also adds quotation marks and escapes the string)
    bool setString(const unsigned int &idx, const std::string &value);
    // sets the value of idx to a given int
    bool setInt(const unsigned int &idx, const int &value);
    // sets the value of idx to a given double
    bool setDouble(const unsigned int &idx, const double &value);
    // sets the value of idx to a given time_t
    bool setTime(const unsigned int &idx, const time_t &value);
    // sets the value of idx to NULL
    bool setNull(const unsigned int &idx);

    // executes a SELECT-statement
    bool ExecuteQuery();
    // executes an UPDATE-statement
    bool ExecuteUpdate();
    // executes an INSERT-statement and returns the last inserted ID
    bool ExecuteInsert();

    //execute a DELETE-statement
    bool ExecuteDelete();

    // builds the query string with filled-in arguments and returns it
    const std::string BuildQueryString();

    // returns a field name
    const std::string getFieldName(const unsigned int &field);
    // gets a string value from the given row and field
    const std::string getString(const unsigned int &row, const unsigned int &field);
    const std::string getString(const unsigned int &row, const std::string &field);
    // gets an int value from the given row and field
    int getInt(const unsigned int &row, const unsigned int &field);
    int getInt(const unsigned int &row, const std::string &field);
    // gets a double value from the given row and field
    double getDouble(const unsigned int &row, const unsigned int &field);
    double getDouble(const unsigned int &row, const std::string &field);
    // gets a time value from the given row and field
    time_t getTime(const unsigned int &row, const unsigned int &field);
    time_t getTime(const unsigned int &row, const std::string &field);

    // returns the result row count
    unsigned int GetResultRowCount();
    unsigned int GetFieldCount();


private:
    typedef std::map<int, std::string> TResultRow;
    MySQLConnection *m_sqlConn;
    int m_iResultRowCount;
    std::string m_sStatement;
    std::map<int, std::string> m_mArgMap;
    std::map<int, TResultRow> m_mResultMap;
    std::map<int, std::string> m_mFieldMap;
    std::map<std::string, int> m_mFieldStringToIntMap;

};

源文件如下:


#include "MySqlQuery.h"
#include <cassert>


MySQLConnection::MySQLConnection()
{
    m_bIsConnected = false;
    m_pMySQLConn = NULL;
    m_sHostname = "";
    m_sUsername = "";
    m_sPassword = "";
    m_wPort = 0;
    m_sSchemaName = "";
}

MySQLConnection::~MySQLConnection()
{
    if(m_pMySQLConn != nullptr)
    {
        std::clog << "Closing MySQL Connection" << std::endl;
        mysql_close(m_pMySQLConn);
    }
}

bool MySQLConnection::Connect(const std::string &sHostname, const uint16_t &wPort, 
	const std::string &sUsername, const std::string &sPassword, const std::string &sDB = NULL)
{
    // If we're already connected, we should close the first connection
    Disconnect();

    m_sHostname = sHostname;
    m_sUsername = sUsername;
    m_sPassword = sPassword;
    m_wPort = wPort;
    m_sSchemaName = sDB;
    m_bIsConnected = false;

    MYSQL *pMySQLConnRet = nullptr;
    m_pMySQLConn = mysql_init(m_pMySQLConn);

    std::clog << "Connection to " << m_sUsername << "@" << m_sHostname << ":" << wPort << "..." << std::endl;

    pMySQLConnRet = mysql_real_connect(m_pMySQLConn, m_sHostname.c_str(), m_sUsername.c_str(), m_sPassword.c_str(), m_sSchemaName.c_str(), m_wPort, NULL, 0);

    if(nullptr == pMySQLConnRet)
    {
        m_bIsConnected = false;
        std::cerr << "Connection failed: " << mysql_error(m_pMySQLConn);
    } 
    else 
    {
        m_bIsConnected = true;
        std::clog << "Connected!" << std::endl;
    }

    return m_bIsConnected;
}

void MySQLConnection::Disconnect()
{
    if(m_bIsConnected)
    {
        mysql_close(m_pMySQLConn);
        m_pMySQLConn = nullptr;
        std::clog << "Disconnected from MySQL DB!" << std::endl;
    }


    m_bIsConnected = false;

}

bool MySQLConnection::SelectDB(const std::string &sSchemaName)
{
    if(!m_bIsConnected)
    {
        std::cerr << "Not connected to MySQL DB!" << std::endl;
        return false;
    }

    if(mysql_select_db(m_pMySQLConn, sSchemaName.c_str()) != 0)
    {
        std::cerr << "Failed to select DB! Error: " << mysql_error(m_pMySQLConn) << std::endl;
        return false;
    } 
    else 
    {
        m_sSchemaName = sSchemaName.c_str();
        std::clog << "Selected database \"" << sSchemaName << "\"" << std::endl;
        return true;
    }
}

const std::string MySQLConnection::GetLastError() const
{
    if(!m_bIsConnected)
    {
        std::cerr << "Not connected to MySQL DB!" << std::endl;
        return "Not connected";
    }

    return (char*)mysql_error(m_pMySQLConn);
}

MYSQL *MySQLConnection::getConn()
{
    return m_pMySQLConn;
}

bool MySQLConnection::IsConnected()
{
    return m_bIsConnected;
}

const std::string MySQLConnection::EscapeString(const std::string &_strValue) const
{
    if(!m_bIsConnected)
    {
        std::cerr << "Not connected to MySQL DB!" << std::endl;
        return "";
    }

    char *pValue = new char[(_strValue.length()*2)+1];
    mysql_real_escape_string(m_pMySQLConn, pValue, _strValue.c_str(), _strValue.length());

    std::string sRet = pValue;
    delete[] pValue;
    pValue = nullptr;

    return sRet;
}

MySQLQuery::MySQLQuery(MySQLConnection *pConn, const std::string &strStatement)
{
    m_sqlConn = pConn;
    m_sStatement = strStatement;
    m_iResultRowCount = 0;

    int argCount = std::count(m_sStatement.begin(), m_sStatement.end(), '?');
    for(int i = 1; i <= argCount; i++)
    {
        m_mArgMap.insert(std::pair<int, std::string>(i, ""));
    }
}

MySQLQuery::~MySQLQuery()
{
}

bool MySQLQuery::setString(const unsigned int &idx, const std::string &value)
{

    if(idx > m_mArgMap.size())
    {
        std::cerr << "Index exceeds total arg count in statement" << std::endl;
        return false;
    }

    std::stringstream ss;
    std::string escapedValue = m_sqlConn->EscapeString(value);
    ss << "\"" << escapedValue << "\"";
    m_mArgMap[idx] = ss.str();

    return true;
}

bool MySQLQuery::setInt(const unsigned int &idx, const int &value)
{
    if(idx > m_mArgMap.size())
    {
        std::cerr << "Index exceeds total arg count in statement" << std::endl;
        return false;
    }

    std::stringstream ss;
    ss << value;
    m_mArgMap[idx] = ss.str();

    return true;
}

bool MySQLQuery::setDouble(const unsigned int &idx, const double &_dValue)
{
    if(idx > m_mArgMap.size())
    {
        std::cerr << "Index exceeds total arg count in statement" << std::endl;
        return false;
    }

    std::stringstream ss;
    ss << _dValue;
    m_mArgMap[idx] = ss.str();

    return true;
}

bool MySQLQuery::setTime(const unsigned int &idx, const time_t &value)
{
    if(idx > m_mArgMap.size())
    {
        std::cerr << "Index exceeds total arg count in statement" << std::endl;
        return false;
    }

    std::stringstream ss;
    ss << value;
    m_mArgMap[idx] = ss.str();

    return true;
}

bool MySQLQuery::setNull(const unsigned int &idx)
{
    if(idx > m_mArgMap.size())
    {
        std::cerr << "Index exceeds total arg count in statement" << std::endl;
        return false;
    }

    m_mArgMap[idx] = "NULL";
    return true;
}

const std::string MySQLQuery::getFieldName(const unsigned int &iField)
{
    if(iField < 1)
    {
        std::cerr << "The field index has to be over 1!" << std::endl;
        return "";
    }
    else if(m_mFieldMap.size() < iField)
    {
        std::cerr << "There are only " << m_mFieldMap.size() << " fields available!" << std::endl;
        return "";
    }

    std::string sFieldName = m_mFieldMap[iField];
    return sFieldName;
}

const std::string MySQLQuery::getString(const unsigned int &row, const unsigned int &iField)
{
    if(GetResultRowCount() < 1)
    {
        std::cerr << "The query didn't return any rows!" << std::endl;
        return "";
    } 
    else if(GetResultRowCount() < row)
    {
        std::cerr << "There are only " << GetResultRowCount() << " rows available!" << std::endl;
        return "";
    } 
    else if(row < 1)
    {
        std::cerr << "The selected row has to be > 1" << std::endl;
        return "";
    }

    TResultRow rSelectedRow;
    rSelectedRow = m_mResultMap[row-1];

    std::string sValue = rSelectedRow[iField];

    return sValue;
}

const std::string MySQLQuery::getString(const unsigned int &iRow, const std::string &strField)
{
    if(GetResultRowCount() < 1)
    {
        std::cerr << "The query didn't return any rows!" << std::endl;
        return "";
    }
    else if(GetResultRowCount() < iRow)
    {
        std::cerr << "There are only " << GetResultRowCount() << " rows available!" << std::endl;
        return "";
    } 
    else if(iRow < 1)
    {
        std::cerr << "The selected row has to be > 1" << std::endl;
        return "";
    }

    TResultRow rSelectedRow;
    rSelectedRow = m_mResultMap[iRow-1];

    int iFieldID = m_mFieldStringToIntMap[strField];
    std::string sValue = rSelectedRow[iFieldID];

    return sValue;
}

int MySQLQuery::getInt(const unsigned int &iRow, const unsigned int &iField)
{
    if(GetResultRowCount() < 1)
    {
        std::cerr << "The query didn't return any rows!" << std::endl;
        return -1;
    } 
    else if(GetResultRowCount() < iRow)
    {
        std::cerr << "There are only " << GetResultRowCount() << " rows available!" << std::endl;
        return -1;
    } 
    else if(iRow < 1)
    {
        std::cerr << "The selected row has to be > 1" << std::endl;
        return -1;
    }

    TResultRow rSelectedRow;
    rSelectedRow = m_mResultMap[iRow-1];

    int iValue = atoi(rSelectedRow[iField].c_str());

    return iValue;
}

int MySQLQuery::getInt(const unsigned int &iRow, const std::string &strField)
{
    if(GetResultRowCount() < 1)
    {
        std::cerr << "The query didn't return any rows!" << std::endl;
        return -1;
    } 
    else if(GetResultRowCount() < iRow)
    {
        std::cerr << "There are only " << GetResultRowCount() << " rows available!" << std::endl;
        return -1;
    } 
    else if(iRow < 1)
    {
        std::cerr << "The selected row has to be > 1" << std::endl;
        return -1;
    }

    TResultRow rSelectedRow;
    rSelectedRow = m_mResultMap[iRow-1];

    int iFieldID = m_mFieldStringToIntMap[strField];
    int iValue = atoi(rSelectedRow[iFieldID].c_str());

    return iValue;
}

double MySQLQuery::getDouble(const unsigned int &iRow, const unsigned int &iField)
{
    if(GetResultRowCount() < 1)
    {
        std::cerr << "The query didn't return any rows!" << std::endl;
        return -1.0;
    } 
    else if(GetResultRowCount() < iRow)
    {
        std::cerr << "There are only " << GetResultRowCount() << " rows available!" << std::endl;
        return -1.0;
    } 
    else if(iRow < 1)
    {
        std::cerr << "The selected row has to be > 1" << std::endl;
        return -1.0;
    }

    TResultRow rSelectedRow;
    rSelectedRow = m_mResultMap[iRow-1];

    double dValue = atof(rSelectedRow[iField].c_str());

    return dValue;
}

double MySQLQuery::getDouble(const unsigned int &iRow, const std::string &strField)
{
    if(GetResultRowCount() < 1)
    {
        std::cerr << "The query didn't return any rows!" << std::endl;
        return -1.0;
    } 
    else if(GetResultRowCount() < iRow)
    {
        std::cerr << "There are only " << GetResultRowCount() << " rows available!" << std::endl;
        return -1.0;
    } 
    else if(iRow < 1)
    {
        std::cerr << "The selected row has to be > 1" << std::endl;
        return -1.0;
    }

    TResultRow rSelectedRow;
    rSelectedRow = m_mResultMap[iRow-1];

    int iFieldID = m_mFieldStringToIntMap[strField];
    double dValue = atof(rSelectedRow[iFieldID].c_str());

    return dValue;
}

time_t MySQLQuery::getTime(const unsigned int &row, const unsigned int &field)
{
    if(GetResultRowCount() < 1)
    {
        std::cerr << "The query didn't return any rows!" << std::endl;
        return -1;
    } 
    else if(GetResultRowCount() < row)
    {
        std::cerr << "There are only " << GetResultRowCount() << " rows available!" << std::endl;
        return -1;
    } 
    else if(row < 1)
    {
        std::cerr << "The selected row has to be > 1" << std::endl;
        return -1;
    }

    TResultRow rSelectedRow;
    rSelectedRow = m_mResultMap[row-1];

    time_t tValue = atoi(rSelectedRow[field].c_str());

    return tValue;
}

time_t MySQLQuery::getTime(const unsigned int &row, const std::string &field)
{
    if(GetResultRowCount() < 1)
    {
        std::cerr << "The query didn't return any rows!" << std::endl;
        return -1;
    } 
    else if(GetResultRowCount() < row)
    {
        std::cerr << "There are only " << GetResultRowCount() << " rows available!" << std::endl;
        return -1;
    } 
    else if(row < 1)
    {
        std::cerr << "The selected row has to be > 1" << std::endl;
        return -1;
    }

    TResultRow rSelectedRow;
    rSelectedRow = m_mResultMap[row-1];

    int iFieldID = m_mFieldStringToIntMap[field];
    time_t tValue = atoi(rSelectedRow[iFieldID].c_str());

    return tValue;
}


unsigned int MySQLQuery::GetResultRowCount()
{
    const int iRowCount = m_mResultMap.size();
    return iRowCount;
}

unsigned int MySQLQuery::GetFieldCount()
{
    const int iFieldCount = m_mFieldMap.size();
    return iFieldCount;
}

const std::string MySQLQuery::BuildQueryString()
{
    // replace each '?' with the corresponding value
    int iLastFoundPos = 0;
    std::string sPreparedStatement;
    sPreparedStatement = m_sStatement;
    for(unsigned int i = 1; i <= m_mArgMap.size(); i++)
    {
        iLastFoundPos = sPreparedStatement.find('?');
        sPreparedStatement.replace(iLastFoundPos, 1, "");
        sPreparedStatement.insert(iLastFoundPos, m_mArgMap[i]);
    }

    return sPreparedStatement;
}

bool MySQLQuery::ExecuteQuery()
{
    std::string sStatement = BuildQueryString();

    if(mysql_query(m_sqlConn->getConn(), sStatement.c_str()))
    {
        std::cerr << "MySQL Error: " << m_sqlConn->GetLastError() << std::endl;
        return false;
    }

    MYSQL_RES *pResult = mysql_store_result(m_sqlConn->getConn());

    if(pResult == NULL)
    {
        std::cerr << "MySQL Error: " << m_sqlConn->GetLastError() << std::endl;
        return false;
    }


    int iNumFields = mysql_num_fields(pResult);
    MYSQL_ROW row;
    MYSQL_FIELD *field;

    // Get field names and store it in the map
    int i = 0;
    while((field = mysql_fetch_field(pResult)))
    {
        m_mFieldMap.insert(std::pair<int, std::string>(i, field->name));
        m_mFieldStringToIntMap.insert(std::pair<std::string, int>(field->name, i));
        i++;
    }

    // Get Rows
    i = 0;
    while((row = mysql_fetch_row(pResult)))
    {
        TResultRow resRow;
        for(int n = 0; n < iNumFields; n++)
        {
            resRow.insert(std::pair<int, std::string>(n, row[n] ? row[n] : "NULL"));
        }

        m_mResultMap.insert(std::pair<int, TResultRow>(i, resRow));

        i++;
    }

    return true;
}

bool MySQLQuery::ExecuteUpdate()
{
    std::string sStatement = BuildQueryString();

    if(mysql_query(m_sqlConn->getConn(), sStatement.c_str()))
    {
        std::cerr << "MySQL Error: " << m_sqlConn->GetLastError() << std::endl;
        return false;
    }

    return true;
}

bool MySQLQuery::ExecuteInsert()
{
    std::string sStatement = BuildQueryString();

    if(mysql_query(m_sqlConn->getConn(), sStatement.c_str()))
    {
        std::cerr << "MySQL Error: " << m_sqlConn->GetLastError() << std::endl;
        return false;
    }

    return true;
}

bool MySQLQuery::ExecuteDelete()
{
	std::string sStatement = BuildQueryString();

	if (mysql_query(m_sqlConn->getConn(), sStatement.c_str()))
	{
		std::cerr << "MySQL Error: " << m_sqlConn->GetLastError() << std::endl;
		return false;
	}

	return true;
}

测试代码如下:

#include "mysqlquery.h"
#include <time.h>
#include <iostream>
using namespace std;

int main()
{

	MySQLConnection mySqlCon;

	if (!mySqlCon.Connect("127.0.0.1", 3306, "root", "123456", "wd"))
	{
		cout << "Error db connection " << endl;
		return 0;
	}

	cout << "Connection Success " << endl;

	MySQLQuery query(&mySqlCon, "SELECT * FROM tbl_student;");
	if (query.ExecuteQuery())
	{
		unsigned int row = query.GetResultRowCount();
		unsigned int col = query.GetFieldCount();
		for (unsigned int r = 0; r < row; ++r)
		{
			cout << "name = " << query.getString(r + 1, "name")
				 << ", age = " << query.getString(r + 1, "age")
				 << ", sex = " << query.getString(r + 1, "sex") << endl;
		}
	}

	MySQLQuery insertQuery(&mySqlCon, "INSERT INTO tbl_student VALUES ('shihan', '12', 1); ");
	if (insertQuery.ExecuteInsert())
	{
		cout << "Success Query Insert" << endl;
	}

	MySQLQuery updateQuery(&mySqlCon, "UPDATE tbl_student SET sex = 1 WHERE  name = 'shihan'; ");
	if (updateQuery.ExecuteUpdate())
	{
		cout << "Success Query Update" << endl;
	}

	MySQLQuery deleteQuery(&mySqlCon, "DELETE FROM tbl_student WHERE  name = 'shihan'; ");
	if (deleteQuery.ExecuteDelete())
	{
		cout << "Success Query Delete" << endl;
	}

	MySQLQuery query1(&mySqlCon, "SELECT * FROM tbl_student;");
	if (query1.ExecuteQuery())
	{
		unsigned int row = query.GetResultRowCount();
		unsigned int col = query.GetFieldCount();
		for (unsigned int r = 0; r < row; ++r)
		{
			cout << "name = " << query.getString(r + 1, "name")
				<< ", age = " << query.getString(r + 1, "age")
				<< ", sex = " << query.getString(r + 1, "sex") << endl;
		}
	}

	mySqlCon.Disconnect();


	
	return 0;
}

有写的不对的,欢迎大佬们指导。。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

C++连接MySQL 操作的封装 的相关文章

  • MySQL - 返回每个 GROUP BY 的 X 个数字

    在此查询中 我指定要返回的汽车型号 硬编码 所以下面的 SQL 返回one每个模型的记录 SELECT FROM main WHERE marka name SUBARU AND model name IMPREZA AND kuzov G
  • 如何调试 MySQL 存储过程?

    我当前的调试存储过程的过程非常简单 我创建一个名为 debug 的表 在存储过程运行时从其中插入变量值 这允许我查看脚本中给定点的任何变量的值 但是有没有更好的方法来调试 MySQL 存储过程 下列debug msg可以调用过程来简单地将调
  • 使用 Hibernate 在 MySQL 中存储字节数组

    我正在尝试保存带有字节数组字段的实体 我在 MySQL 数据库之上使用 Hibernate 和 JPA 这是字段定义 对于嵌入式 H2 数据库来说效果很好 Entity name blob public class Blob Lob Bas
  • 如何在不超时的情况下解析大型 CSV 文件?

    我正在尝试解析 50 MB 的 csv 文件 文件本身很好 但我正在尝试解决所涉及的大量超时问题 每个设置上传明智 我可以轻松上传并重新打开文件 但浏览器超时后 我收到 500 内部错误 我的猜测是我可以将文件保存到服务器上 打开它并保留我
  • MySQL有两个不同的密码?

    我确信它们是不同事物的密码 但我不确定是什么 当在终端连接到 MySQL 时 我输入 usr LOCAL mysql BIN mysql h host u username p然后系统会提示我输入密码 密码是 但是当使用 PHP 连接到 M
  • 通过我的java代码导出数据库

    我想使用我的 java 代码导出我的 MySQL 数据库 但我还没有找到任何办法 我想要做的就是我的应用程序中有一个按钮作为 导出数据库 单击该按钮时 我的数据库应导出到指定的路径 我使用了以下代码 但它不起作用 Runtime runti
  • MySQL Workbench 6.0 错误无法获取管理员的管理访问权限?

    我在这里使用 MySQL Workbench 6 0 当我选择服务器状态时 出现此错误 对此 我尝试在Google和StackOverflow上寻找解决方案 e g 这个结果 https stackoverflow com question
  • SQL统计高于和低于平均分的学生人数

    我在下面有一个示例表 我试图获取高于平均分数的学生人数和低于平均分数的学生人数 name subject classroom classarm session first term score first term grade std1 m
  • MYSQL 查询返回“资源 id#12”而不是它应返回的数值

    不知道为什么 但这返回了错误的值 我正在取回此资源 ID 12 而不是我正在寻找的数值 1 执行此操作的代码是 type SELECT account type from user attribs WHERE username userna
  • Codeigniter 加入多个条件

    我正在使用 Codeigniter Active Records 课程 我想加入我的users与我的桌子clients表 这样我就可以显示用户的 真实 姓名 而不仅仅是他们的 ID 这是什么clients表看起来像 示例 列 a 1 a 2
  • MySQL 按主键排序

    某些 SQL 服务器允许使用通用语句 例如ORDER BY PRIMARY KEY 我不相信这适用于 MySQL 是否有任何此类解决方法可以允许跨多个表自动选择 或者是否需要查找查询来确定主键 我一直在研究的解决方法包括调用SHOW COL
  • 无法使用 Django 应用程序从容器连接到 MySQL docker 容器

    当我尝试从运行 Django 应用程序的 docker 容器连接到运行 MySQL 的容器时 出现以下错误 django db utils OperationalError 2003 Can t connect to MySQL serve
  • 将 UPDATE 转换为 INSERT INTO ON DUPLICATE KEY UPDATE 语句

    我有这个 UPDATE MySQL 语句 效果很好 UPDATE table1 Inner Join table2 ON table2 id table1 gw id SET table1 field1 1 table1 field2 2
  • MySQL+子串怎么做? + 替换?

    我不太擅长 SQL 希望能够变得更好 我在尝试执行某些表操作时遇到一些麻烦 我希望能够从下面的 ProgUID 列中选择子字符串 就像是 SUBSTRING table ProgUID 3 12 这将为我提供 ProgUID P CAMVE
  • mySQL MATCH 跨多个表

    我有一组 4 个表 我想对其进行搜索 每个都有全文索引 查询可以使用每个索引吗 CREATE TABLE categories id int 5 unsigned NOT NULL auto increment display order
  • 将记录分成两列

    我的数据库中有一个 学生 表 其中包含大约 5 000 条记录 我想将这些记录显示在two分区 如何在不执行查询两次的情况下做到这一点 仅使用单个查询 显示示例http www freeimagehosting net uploads f1
  • 社交应用程序的数据库设计和优化注意事项

    通常的情况 我有一个简单的应用程序 允许人们上传照片并关注其他人 因此 每个用户都会有类似 墙 或 活动源 的东西 他或她可以在其中看到他 她的朋友 他或她关注的人 上传的最新照片 大多数功能都很容易实现 然而 当涉及到这个历史活动源时 由
  • ActiveRecord3死锁重试

    Rails 3 或 ActiveRecord 3 是否有任何插件可以复制旧版本死锁重试 http agilewebdevelopment com plugins deadlock retry插入 或者 该插件仍然适用于 Rails 3 吗
  • mysql-如何向列申请补助?

    用户名 撤销对数据库的选择 Person I set GRANT SELECT id ON database Person TO username localhost 不是工作 gt SELECT secret FROM Person Go
  • 如何在 Laravel 查询中使用多个 OR,AND 条件

    我需要 Laravel 查询帮助 我的自定义查询 返回正确结果 Select FROM events WHERE status 0 AND type public or type private 如何写这个查询Laravel Event w

随机推荐