Accessing MySQL Data from phpMyAdmin with JavaScript

Status
Not open for further replies.

dnarrowx

New Member
Messages
4
Reaction score
0
Points
1
Hello there,

I'll begin by saying that I've been looking for a similar question for several hours now to no avail -- I'm sorry if it's been asked tons of times already!

I started out as a front-end developer and now I need to dive into the back-end.

I made a fairly large MySQL database with lots of scientific data stored on two tables. I imported it into my x10 server by using phpMyAdmin and I can run queries from the SQL tab as normal.

I also have a JavaScript-HTML-CSS page hosted on the same account on x10. The page needs access to that MySQL data, but I have no idea how to use phpMyAdmin to start serving out the data in a JSON object or something, that I can then retrieve using my JavaScript-based site.

Any ideas?
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
You cannot work through phpMyAdmin via script (to my knowledge)
The way to do it:

Your JavaScript calls a PHP page, say information.php. You can use GET or POST and pass values to the script.
information.php uses those values to construct an SQL query (Google "SQL injection attack" to find security considerations)
It then runs the query on you database (using PDO, do not use the deprecated mysql_ functions) and gets a result.
It then takes the result and forms the reply as JSON.
It then returns the JSON.
 

dnarrowx

New Member
Messages
4
Reaction score
0
Points
1
You cannot work through phpMyAdmin via script (to my knowledge)
The way to do it:

Your JavaScript calls a PHP page, say information.php. You can use GET or POST and pass values to the script.
information.php uses those values to construct an SQL query (Google "SQL injection attack" to find security considerations)
It then runs the query on you database (using PDO, do not use the deprecated mysql_ functions) and gets a result.
It then takes the result and forms the reply as JSON.
It then returns the JSON.

Thank you very much for that, but I need some details:
1. What are the URL(s) for my database, if it's hosted on x10 with phpMyAdmin?
2. When I create a PHP page, do I simply add it to the file manager and then refer to in my main webpage, both hosted on my x10 account?

Thank you!
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
Your database does not have a URL. You cannot access it from outside your account. From inside your account, you use "localhost"

You just add the PHP page to the FileManager somewhere (can be in a subdirector of) in /public_html
This means that anybody can access it from the web, not just your JavaScript.
 

dnarrowx

New Member
Messages
4
Reaction score
0
Points
1
Your database does not have a URL. You cannot access it from outside your account. From inside your account, you use "localhost"

You just add the PHP page to the FileManager somewhere (can be in a subdirector of) in /public_html
This means that anybody can access it from the web, not just your JavaScript.

I guess then I'm going to have to set up my own local server to emulate the x10 host. The reason I ask is because I need to develop locally. That shouldn't be too hard.

Thank you, descalzo. Do I have to close the thread, or can I keep it open in case I run into a roadblock?
 

dnarrowx

New Member
Messages
4
Reaction score
0
Points
1
Hello again,

I'm just working on converting my data structure to JSON now.

Once I create several JSON objects, how do I serve them up in a way that the user (client-side) can choose which objects to load?
 
Status
Not open for further replies.
Top