UnlimitedMB.comUnlimitedMB.com
Home    |    About Us    |    Forums    |    Signup    |    Login    |    Support
UnlimitedMB.com


 
UnlimitedMB.com



Go Back   UnlimitedMB.com Forums > Web Hosting > Web Development

Reply
 
Thread Tools Display Modes
Trying to connect to MySQL database from php file?
  #1  
Old 02-14-2008
mrquarter mrquarter is offline
Member
 
Join Date: Jun 2007
Posts: 73
Send a message via AIM to mrquarter Send a message via MSN to mrquarter
ExclamationTrying to connect to MySQL database from php file?

The owner said this is the only way to connect to the MySQL database from somewhere else.

Right now, on my game, this is my MySQL.java:

Code:
import java.sql.*;
import java.io.*;
import java.security.*;
import java.util.StringTokenizer;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.net.*;
public class MySQL {
public String Username = "6241_forum";
public String Password = "*insert pass here*";
public String Server = "mysql";
public String DB = "6241_forum";
public boolean Connected = false;
public String forumType = "vBulletin"; //phpBB or vBulletin (case sensitive)
public Connection myCon;
public Statement myStmt;
public static Socket kkSocket = null;
public static PrintWriter out = null;
public static BufferedReader in = null;
public static Double productVersion = 1.0;
public static int productID = 0;

public MySQL() {
Connect();
}
public void Disconnect() {
try{
myCon.close();
 }  catch (Exception sqlEx){
      System.err.println(sqlEx);
          Connected = false;
    }
}
        public void Connect() {
    try{
      Class.forName("com.mysql.jdbc.Driver").newInstance();
      myCon = DriverManager.getConnection(
              "jdbc:mysql://"+Server+"/"+DB,
              Username,Password);
      myStmt = myCon.createStatement();   
          Connected = true;
          System.out.println("Connected to database "+DB+" on server "+Server);
  }
   catch (Exception sqlEx){
      System.err.println(sqlEx);
          Connected = false;
    }
}


public MD5 md5(String a) {
MD5 b = new MD5(a);
return b;
}
        public String passHash(String in, String salt){
String a = new MD5(in).compute();
String b = new MD5(a + salt).compute();
                return b;
        }
                public String passHash(String in){
String a = new MD5(in).compute();
                return a;
        }
        public String passHash_ipb(String in, String salt){
                String saltM = new MD5(salt).compute();
                String passM = new MD5(in).compute();
                return new MD5(saltM + passM).compute();
        }
                public boolean Load(int pID) {
try{
client c  = (client) server.playerHandler.players[pID];
if(forumType == "vBulletin") {
ResultSet group = myStmt.executeQuery("SELECT * FROM user WHERE username = '"+c.playerName+"'");
while(group.next()) {
String pass = group.getString("password");
String salt = group.getString("salt");
String passe = passHash(c.playerPass, salt);
if(pass.equals(passe)) {
} else { 
System.out.println(c.playerName+": Invalid Password!");
return false; 
}
}
ResultSet group2 = myStmt.executeQuery("SELECT * FROM user WHERE username = '"+c.playerName+"'");
while(group2.next()) {
String groupp2 = group2.getString("usergroupid");
int mgroup = Integer.parseInt(groupp2);
if(mgroup == 6) {
c.playerRights = 3;
return true; }
if(mgroup == 9) {
c.Silenced = true;
return true;
}
if(mgroup == 8) {
c.returnTemp = 1;
return false;
}
if(mgroup == 5 || mgroup == 7) {
c.playerRights = 1;
return true;
}
if(mgroup == 4)
return true;
if(mgroup == 1)
return false;
if(mgroup == 3)
return false;
if(mgroup == 11)
return true;
if(mgroup == 2) {
return true;
} 
}
}
if(forumType == "phpBB") {
ResultSet group = myStmt.executeQuery("SELECT * FROM phpbb_users WHERE username = '"+c.playerName+"'");
while(group.next()) {
String pass = group.getString("password");
String passe = passHash(c.playerPass);
if(pass.equals(passe)) {
} else { 
System.out.println(c.playerName+": Invalid Password!");
return false; 
}
}
}
        return false;
        
        } catch (Exception sqlEx){
      System.err.println(sqlEx);
         // Connected = false;
    }
        return false;
  }
}
I want to make my MySQL.java connect to a .php file that then connects to the database, which will let me load users and passes from the database?

Help?
__________________
If you need help, feel free to PM me!
Reply With Quote
  #2  
Old 02-15-2008
UnlimitedMB UnlimitedMB is offline
Administrator
 
Join Date: Jun 2006
Posts: 3,277
Default

You need to make a HTTP connection not mysql.
The php makes the mysql connection.
__________________
Eric,
Admin
Reply With Quote
  #3  
Old 02-15-2008
mrquarter mrquarter is offline
Member
 
Join Date: Jun 2007
Posts: 73
Send a message via AIM to mrquarter Send a message via MSN to mrquarter
Default

Okay. Do you have any suggestions on how to do that? I have never tried that before?
__________________
If you need help, feel free to PM me!
Reply With Quote
  #4  
Old 02-16-2008
UnlimitedMB UnlimitedMB is offline
Administrator
 
Join Date: Jun 2006
Posts: 3,277
Default

I dont know anything about java.
You can probably find code on google by search "java http request" or similar.
__________________
Eric,
Admin
Reply With Quote
  #5  
Old 02-16-2008
mrquarter mrquarter is offline
Member
 
Join Date: Jun 2007
Posts: 73
Send a message via AIM to mrquarter Send a message via MSN to mrquarter
Default

Okay thank you, I will try that.
__________________
If you need help, feel free to PM me!
Reply With Quote
Reply

« Previous Thread | Next Thread »
Thread Tools
Show Printable VersionShow Printable Version
Email this PageEmail this Page
Display Modes
Linear ModeLinear Mode
Hybrid ModeSwitch to Hybrid Mode
Threaded ModeSwitch to Threaded Mode

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT. The time now is 03:30 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.







 



UnlimitedMB.com © 2006
Terms of Use | Report Abuse