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?
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?
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
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?
You can find an example here: http://www.js-examples.com/page/javascripts__example.html?id=847
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.j dbc.Driver ").newInst ance();
con = DriverManager.getConnectio n("jdbc:my sql:///tes t",
"root", "secret");
if(!con.isClosed())
System.out.println("Succes sfully connected to " +
"MySQL server using TCP/IP...");
} catch(Exception e) {
System.err.println("Except ion: " + e.getMessage());
} finally {
try {
if(con != null)
con.close();
} catch(SQLException e) {}
}
}
}
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.j
con = DriverManager.getConnectio
"root", "secret");
if(!con.isClosed())
System.out.println("Succes
"MySQL server using TCP/IP...");
} catch(Exception e) {
System.err.println("Except
} 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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
the server has php
Good call hernst42.
chippyles, hernst42 is probably the easiest most effective way to incorporate your database into your website.
chippyles, hernst42 is probably the easiest most effective way to incorporate your database into your website.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.