0

I'm trying to connect to my SQL server via Javascript. In order to do this, I have to execute some PHP code, but I'm having some trouble with that.

At the moment I use this code to execute a PHP script, without success

function testConnection()
{
    $.get("script/SQL/testConnection.php");
}

How is it possible to execute some PHP code, or connect to the server and execute SQL queries?

Thanks Matt

SachinGutte
  • 6,947
  • 5
  • 35
  • 58
Matt
  • 1,893
  • 11
  • 33
  • 57
  • From what environment, a web browser? – T.J. Crowder May 20 '13 at 14:30
  • 1
    You cannot connect directly from Javascript to MySQL\* (unless you want to expose your entire database to the public internet). Javascript talks to PHP talks to MySQL. (\* meaning in the context of Javascript === browser) – deceze May 20 '13 at 14:30
  • 1
    So how do you tell that your script does not succeed? – crackmigg May 20 '13 at 14:31
  • I think u can use .load in juqery to load the php code – underscore May 20 '13 at 14:32
  • Javascript: `Hey PHP script do me a favor and look something up for me while I wait asynchronously`, PHP script: `Alright here are your results`, Javascript: `Thanks, now my wait is over and I can finally do something with the data in the callback`. That's how it works fundamentally. – dan-lee May 20 '13 at 14:33
  • Since everybody is suggesting I should take a look at the duplicate I will. Thanks – Matt May 20 '13 at 15:08

1 Answers1

1

That $.get call you have is a relative URL. Let's say your user is on page domain.com/home/. If you use that code block, the user's browser is going to make a GET request to domain.com/home/script/SQL/testConnection.php. Is that what you are expecting?

What HTTP status code are you receiving back?

thatidiotguy
  • 8,701
  • 13
  • 60
  • 105