Link to home
Start Free TrialLog in
Avatar of chippyles
chippyles

asked on

connecting to mySQL database using javascript or html

I have a website that has a mySQL database on it.
Server: mysql.gpyles.com
DB: gpyles
Table: Contacts

Code:
CREATE TABLE `Contacts` (
`FName` VARCHAR( 20 ) NOT NULL ,
`LName` VARCHAR( 50 ) NOT NULL ,
`Phone` VARCHAR( 20 ) NOT NULL
) ENGINE = MYISAM ;

How can I connect to this using java script or html?

Avatar of hernst42
hernst42
Flag of Germany image

not possible with JavaScript or HTML as both don't have a connectivitiy to mysql. It is possible to create on a server HTML with a server side language like PHP ASP, JSP
Avatar of chippyles
chippyles

ASKER

I need to know the easiest and most cost effective way to connect to mySQL.  Can you guide me to how I would do that and a simple PHP script?  Is there a way to embed PHP into my web page?
The first thing you're going to need is a DB driver.
If you want to use Java, you'll need to have a JDBC driver installed on the server that houses
the Java and MySQL source. If you intend on using JDBC or Java to connect to the servers database your going to need the strings to do so. There's many Java scripts out there to establish a connection to the database. Here's some source to get you start as an example:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class JdbcExample2 {

  public static void main(String args[]) {
    Connection con = null;

    try {
      Class.forName("com.mysql.jdbc.Driver").newInstance();
      con = DriverManager.getConnection("jdbc:mysql:///test",
        "root", "secret");

      if(!con.isClosed())
        System.out.println("Successfully connected to " +
          "MySQL server using TCP/IP...");

    } catch(Exception e) {
      System.err.println("Exception: " + e.getMessage());
    } finally {
      try {
        if(con != null)
          con.close();
      } catch(SQLException e) {}
    }
  }
}
Sorry, my example link does not respond to your request. You have to use a server-side language like PHP, Java, Ruby, ...
ASKER CERTIFIED SOLUTION
Avatar of hernst42
hernst42
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
the server has php
Good call hernst42.
chippyles, hernst42 is probably the easiest most effective way to incorporate your database into your website.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial