First I want to say that I am so appreciated that if anyone can tell me the right solution. And It is my pleasure if we can solve the problem together.
Background:
I’m looking for a job in programming by using the Unreal Engine. And I think that if I can connect the engine with the database for example MySQL, the companies would be more willing to hire me.
So, I have spent days trying to do this. Fail and fail again.
Maybe I’m starting from the wrong place at all.
My code is like below:
void AMySQLConnector::BeginPlay()
{
Super::BeginPlay();
//连接标准语句
AMySQLConnector::MyServerAddress = "127.0.0.1";
AMySQLConnector::MyDataBase = "test";
AMySQLConnector::MyUsername = "root";
AMySQLConnector::MyPassword = "123456";
FString ConnectionString = "server=127.0.0.1;uid=root;pwd=123456;database=test";
//连接
if (MySQLConnection.Open(nullptr, *MyServerAddress, *ConnectionString)) {
GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Yellow, "Connection ready.");
int32 id = 1;
FString QueryString1 = "USE test";
FString QueryString2 = "INSERT INTO ue_test(testINT) VALUES(3)";
FDataBaseRecordSet* MySQLRecordSet;
MySQLConnection.Execute(*QueryString1, MySQLRecordSet);
if (MySQLConnection.Execute(*QueryString2, MySQLRecordSet)) {
GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Yellow, "Execution succeeded.");
//FString ColumnString = "mag";
//int32 TestN = 5;
//FString result = FString::SanitizeFloat(MySQLRecordSet->GetFloat(*ColumnString), TestN);
//GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Yellow, result);
}
}
else {
GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Yellow, "Database connection failed.");
}
}
I am 100% sure that my MySQL database is running because I can access the database using the workbench. And the password and user-id should be all right.
Problem:
This can output the “connection ready” and “Execution succeeded”.
But the table in the database didn’t change. And I can access nothing in the MySQLRecordSet.
I have been confused for days. And I have to send my resume to the company in half a month. If anyone can help me, thank you very much!
Sincerely, a student who loves games very much and wants to contribute to the game industry.