Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ SQL » MySql.cpp (MySqlSession::Connect)
MySql.cpp (MySqlSession::Connect) [message #4376] Thu, 03 August 2006 17:49 Go to previous message
Ptomaine is currently offline  Ptomaine
Messages: 11
Registered: July 2006
Promising Member
Hi there!
It would be much more better to know an error if a connection failed. Here is the draft code to implement the task.

bool MySqlSession::Connect(const char *user, const char *password, const char *database,
                           const char *host, int port, const char *socket) {
	mysql = mysql_init((MYSQL*) 0);
	if(mysql && mysql_real_connect(mysql, sEmpNull(host), sEmpNull(user),
		                           sEmpNull(password), sEmpNull(database), port,
								   sEmpNull(socket), 0)) {
		Sql sql(*this);
		username = sql.Select("substring_index(USER(),'@',1)");
		return true;
	}

       errorstatement = mysql->net.last_error-2; //we must substract 2 to fix MySQL Server 5.0.19 bug.


        Close();
	return false;
}

[Updated on: Thu, 03 August 2006 17:53]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: SqlArray Accept() Enables controls
Next Topic: build CppSQLite failed
Goto Forum:
  


Current Time: Tue May 14 09:20:39 CEST 2024

Total time taken to generate the page: 0.03122 seconds