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?

Web DevelopmentMicrosoft Legacy OSMySQL Server

Avatar of undefined
Last Comment
rdivilbiss
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?
Avatar of fpthree
fpthree

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) {}
    }
  }
}
Avatar of elfe69
elfe69
Flag of Switzerland image

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

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of chippyles
chippyles

ASKER

the server has php
Avatar of fpthree
fpthree

Good call hernst42.
chippyles, hernst42 is probably the easiest most effective way to incorporate your database into your website.
SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
SOLUTION
Avatar of rdivilbiss
rdivilbiss
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Web Development
Web Development

Web development includes all aspects of presenting content on intranets and the Internet, including delivery development, protocols, languages and standards, server software, browser clients, databases and multimedia generation.

77K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo