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)
-
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_Startedapsillers– apsillers2013年01月17日 18:19:41 +00:00Commented 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.David Harris– David Harris2013年01月17日 18:19:49 +00:00Commented Jan 17, 2013 at 18:19
-
It is not possible at client side.Roopendra– Roopendra2013年01月17日 18:21:23 +00:00Commented Jan 17, 2013 at 18:21
-
@Senen I have posted a way in which you can access the PHP/SQL values in Javascript below.Alex W– Alex W2013年01月17日 18:35:24 +00:00Commented Jan 17, 2013 at 18:35
1 Answer 1
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.