0

Suppose I define a an application in php which has as into the Tag as an internal javascript and a variable 'abc' defined into the js as follows :

var abc;

now i want to assign a new value to the variable which will be fetched from a MySQL db

example :

var abc = $mysql(select id from dB_table where .....xyz )

will it be under the scope of abc to retrieve date from MySQL db? how is it achievable?

PS : i will be using php to connect to the db

mysql_connect(servername,username,password)
4
  • If you want to perform this update any time after page-load time, you'll want to fetch a new value from the server with Ajax: developer.mozilla.org/en-US/docs/AJAX/Getting_Started Commented Jan 17, 2013 at 18:19
  • So wait.. You want to use JavaScript to connect to your database? Not only is that very difficult, it's a terrible idea. Commented Jan 17, 2013 at 18:19
  • It is not possible at client side. Commented Jan 17, 2013 at 18:21
  • @Senen I have posted a way in which you can access the PHP/SQL values in Javascript below. Commented Jan 17, 2013 at 18:35

1 Answer 1

5

STOP STOP STOP STOP. Horribly stupid idea... if you're specifying SQL in client-side code, what's to stop someone from doing

var haha_im_in_ur_server = $mysql("delete from db_Table");

THINK about how extraordinarily dangerous such a system will be. If you enjoy getting your server destroyed in a every-other-second basis, then feel free to implement it yourself.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.