Online Shopping : Computers : Programming : Languages : JavaScript : Database

+ Search
Add Entry AlertManage Folder Edit Entry Add page to
Did You Find This Entry Useful?

184 of 274 people (67%) answered Yes
Recently 5 of 10 people (50%) answered Yes


JavaScript: How should i connect MySql database through JavaScript ?

Apr 2nd, 2009 07:29
engatoo engatoo, alex martin, Knud van Eeden, Colin Fraser, Jean-Bernard Valentaten, DILIP RAMAKRISHNAN,

Using only javascript, there is no way of doing so.
You will have to use a server-based script language (e.g. ASP, PHP, 
JSP ...).
--- Knud van Eeden - 18 September 2001 - 02:35 -----------------------
Computer: Language: Interpreter: JavaScript: How should I connect mysql
database through JavaScript?
Method: ActiveX
Create e.g. an executable (which handles the database) and load it as
an ActiveX control in your client side webpage
Delphi: ActiveX Control: Create: Simple: How to create a Delphi 
executable and run it in IE browser?
Method: Supply filename to run as a URL
Possible *idea* for a solution:
(for example only if you insist to do it on the client side, e.g. your
own computer, you have no webserver running, and have only your
webbrowser to work with. So it can be seen as some possible
workaround. For example, most large IT organizations do not allow you 
run a (personal or local) web server, though you possibly might run a
(personal or local) database, so you are forced to look for some
In general,
you can load and or run ANY executable file
(thus files with extension .exe, .com or .bat),
on the client side (or server side) in your browser,
via the JavaScript commands:
(the only price you have to pay here, is always an extra
 confirmation click for that file, to 'Open' or 'Run this program from
 its current location', when asked for)
 for example:
  document.location.href="c:/program files/merlin/bin/mysql.exe";
(if you use pure HTML, use
  <A HREF="yourexefile"> run your exe file </a>
  <A HREF="yourcomfile"> run your com file </a>
  <A HREF="yourbatchfile"> run your batch file </a>
for example:
  <A HREF="c:\program files\merlin\bin\mysql.exe"> run your exe file
[Internet: see also:
You call then your MySql .exe, read the output with an external
program (e.g. written in VisualBasic, C++, Java, batch file, ...), and
generate dynamically an HTML file.
This HTML file output you read in your browser.
Possible idea of a scenario:
1. Make sure you have MySql installed
   (e.g. download the free MySql light database from
    (after registering first, by clicking on the
    left side on 'Click here to register')
2. Create (by hand or dynamically) the SQL input for MySql
   for example:
   (Here we create the input by hand, so type the following text in
your favorite wordprocessor
   and save it e.g. as
   USE mydatabaseexample;
   CREATE TABLE mytableexample ( userinfo VARCHAR( 79 ), productname
VARCHAR( 20 ), quantity VARCHAR( 5 ), creditcardnumber VARCHAR( 16 ),
creditcardnumberexpdate VARCHAR( 10 ), creditcardnumbername VARCHAR(
40 ), creditability VARCHAR( 20 ) );
   INSERT INTO mytableexample ( userinfo , productname , quantity ,
creditcardnumber , creditcardnumberexpdate , creditcardnumbername ,
creditability ) VALUES ( 'ElectionDatabase' , 'not found' , 'not
found' , 'not found' , 'not found' , 'not found' , 'not found' );
   SELECT * FROM mytableexample;
3. So create any batch file, containing the path to your MySql .exe 
   and create dynamically by printing e.g. an HTML, JS or XML file
   from your output.
   (You will have to do some extra programming to create your
   MySQL SQL input and create dynamically the MySQL output)
   for example:
   (Type the following text in your favorite wordprocessor,
   and save it e.g. as
    REM change here the path to your mysql .exe
    SET mysqlpathexe=c:\progra~1\merlin~1\mysql\bin
    REM change here the path to your mysql input
    SET mysqlpathinput=c:\bbc\taal
    REM change here the path to your mysql output
    SET mysqlpathoutput=c:\bbc\taal
    %mysqlpathexe%\mysqladmin.exe create mydatabaseexample
    %mysqlpathexe%\mysql.exe <%mysqlpathinput%\mysqlin.sql >%
4. Create an HTML file, say c:\mysqloutput.htm,
   (in this simplest case it is not necessary to create this file,
    as redirection (using '>') of the MySql output text to a file is
    here with extension .htm, so you see thus just the output text
    HTML markup tags like <HTML>, <BODY>, ...). More general, you
    will have to generate this by printing it, e.g. using print
    commands in that language like printf( "<HTML>",
    document.write( "<HTML>" ); echo <HTML>, or similar)
5. Create the JavaScript commands to run MySql .exe and capture
   the generated MySql output
   for example:
   (Type the following text in your favorite wordprocessor,
   and save it e.g. as
   -- you will have to change the path, here is used c:/bbc/taal --
    1. Run MySql batch file
     onClick=' "file:///c:/bbc/taal/mysqlout.htm" );'
    2. Get MySql output file
6. Then start your browser, and load this file (say mysqlrun.htm)
   in your browser (e.g. by typing the URL of the path to this file,
   say c:\mysqlrun.htm, or by typing
    start mysqlrun.htm
   on the DOS command line)
   Then clicking first on the button 'Run MySql batch file' will call
   MySql .exe, input your SQL commands (e.g. via redirection '<'),
   and generate an SQL output file (e.g. via redirection '>').
   Then your external program should convert this output to HTML.
   Via after that pressing the button 'Get MySql output' you then read
   your MySql output text in your browser.
PS choose to 'Open'
   'Run this program from its current location'
   that executable file when asked after clicking the appropriate 
PS Filenames in JavaScript:
   remember to use forward slash '/' in your filename(s),
   if appropriate, or that file or page might or will not be found
   thus for example use:
   and not
  or similarly use double backward slashes '\\' in your filename(s)
  (the first of the two backslashes is all the time used for escaping)
   thus for example use:
   and not
  If you use filenames in pure HTML, you can just use the normal
  filename notation (like c:\mysqlrun.bat).
Method: MacroMedia ActionScript / Adobe JavaScript
The History of JavaScript and Databases
Internet: see also:
JavaScript: Database: Overview: Can you give an overview of links?
Colin Fraser:
I doubt this is actually workable on a web server to provide a result 
a remote computer. This is long winded and convoluted code that I
suggest would collapse if a gentle breeze was blowing out of the
north-east. It is also the kind of code that i would rail against if 
of my team was to offer it up as a potential solution. It is far 
to use appropriate server-side scripting like PHP. 
I have found PHP to be relatively easy to learn, easy to use, with a
smaller overhead than ASP, or JSP, and considerably faster to run than
those, CFM and Java.