JavaScript 㧠SQL - AjaSQL
All About 㧠JavaScript ã®ã¬ã¤ããå¤ãã¦ããé«æ©ãã ã AjaSQL ãªã JavaScript (+PHP)ã®ã©ã¤ãã©ãªãå ¬éãã¦ãã¾ãã
ãAjaSQLã¯ãJavaScriptããSQLæãAjaxçºè¡ãããµã¼ãã¼å´ã®ã²ã¼ãã¦ã¨ã¤ãçµç±ãã¦ããã¼ã¿ãã¼ã¹(MySQL,SQLite...)ã¸æ¥ç¶ãçµæã»ãããJavaScriptã§Ajaxåä¿¡ãããã¼ã«ã§ãã
ãåºæ¬æ§æã¯ãAjaxã©ã¤ãã©ãªï¼jslb_ajaxXXX.jsï¼ãAjaSQLã©ã¤ãã©ãªï¼jslb_ajasqlXXX.jsï¼ã¨PHPã«ããAjaSQLã²ã¼ãã¦ã¨ã¤ï¼ajasql_gwXXX.phpï¼ããã³ããã¼ã¿ãã¼ã¹(JavaScriptå´ããSQLiteãMySQLãé¸æå¶å¾¡)ã§ãã
ãAjaSQLã使ããã¨ã§ãä»ã¾ã§ããµã¼ãã¼å´ãã²ã¨ãã§ä¸æã«å¼ãåãã¦ããã SQLãã¼ã¿ãã¼ã¹ã®å¦çããAjaxéä¿¡ã«ãããã¯ã©ã¤ã¢ã³ãå´JavaScriptã¸åæ£ãããã¨ãå¯è½ã«ãªãã¾ãã
ã§ãæ°ã«ãªã£ã¦ã¡ãã£ã¨å®è£ ãè¦ããã¦ããã£ãã®ã§ããã"è² è·ã軽æ¸ããããã¨ãã§ãã"ã¨ããã®ã¯ã¡ã¨ã§ãããããªã¨ããã®ã©ã¤ãã©ãªããã£ã¦ãã®ã¯ãJavaScript ã«åãè¾¼ã¾ãã SQL ã XMLHttpRequest ã§ãPHP ã§æ¸ããã DB proxy (ã²ã¼ãã¦ã§ã¤)ã«é£ã°ãã¦åºåãåãåãã¨ãããã®ã
ããã¥ã¢ã«ã«ã¯ HTML ã XML ã¨ãã¦ãã¼ã¿ãããã¨ãããããã¨ã¯ãªãã®ã§è² è·åæ£ã«ãªãã¾ãã£ã¦ãããã§ãããDB ã®ãã¼ã¿ã HTML ã XML ã«å¤æããã¨ãããã¼ã¿ã HTML ã XML ã«ãªãåãµããã¡ãã£ã¨ã®åé·æ§ããã¢ããªã±ã¼ã·ã§ã³å ¨ä½ã®å¦çã§æ¯é çã«ãªããªãã¦ãã¨ã¯ãããªã«ãªãã¨æãã®ã§ããJavaScript ããç´æ¥ãã¼ã¿ãã¼ã¹ã«æ¥ç¶ãããªãã¨ããããéã« PHP ã§æ¸ããããµã¼ãã¼ãµã¤ãã®ããã°ã©ã ãæã¾ã£ã¦ãã以ä¸ã¯ããã®ä¸ã§ HTML ãããã XML ãçæãããããã®ã¨ã»ã¨ãã©å¤ãããªãããããªãããªã(ããããã²ã¼ãã¦ã§ã¤ã®å®è£ ã¯PHPã ãï½) ãã¨ãPHP ã®ä¸ã§ mysql ã¨ã sqlite ã®ã³ãã³ããå¤é¨å¼åºããã¦ãã®ã§ããµã¼ãã¼ãµã¤ãããã°ã©ã ã§ç´æ¥ãã¼ã¿ãã¼ã¹ã«æ¥ç¶ãã«ãããããããé ãã¨æãã¾ãã
ãã®ã©ã¤ãã©ãªã®ããã¨ããã¯è² è·åæ£ã¨ããã¨ãããããªãã¦ããµã¼ãã¼ãµã¤ãã®ã³ã¼ããããããªãã¦ããã¯ã©ã¤ã¢ã³ãããã°ã©ã ã§ãã¼ã¿ãã¼ã¹ãã³ããªã³ã°ãã§ããã£ã¦æãªããããªãããªã
(ã¡ããã¨è¦ã¦ãªããã§ã§ãããã©ããããããªããã ãã©) AjaSQL ã©ã¤ãã©ãªã¨ã²ã¼ãã¦ã§ã¤ã¯åããµã¼ãã¼ã«ç½®ãã¦ããã¦ãAjaSQL ã©ã¤ãã©ãªãã¯ã©ã¤ã¢ã³ããã script å¤é¨å¼åºãã§èªã¿è¾¼ããããã«ããã°ãã©ã¤ãã©ãªã«å®ç¾©ããã¦ããé¢æ°ã使ããã®ã§ãã¯ã©ã¤ã¢ã³ãå´ã®ä¿®æ£ã ãã§ãã¼ã¿ãã¼ã¹ãã好ããªãã¼ã¿ãåã£ã¦ããã...ã¨èããã¨çµæ§é¢ç½ã試ã¿ã«ãæãã¦ãã¾ãã
åãªããã²ã¼ãã¦ã§ã¤ãXMLHttpRequest 㧠SQL ãçºè¡ããã©ã¤ãã©ãªã«å ãã¦ãJavaScript ã«ãã O/R ãããã追å ããä¸å±¤æ§é ã«ããããªãO/R ãããã¯æ±ç¨çãªã¤ããã«ãªã£ã¦ãã¦ã(Perl ã§ããã¨ããã® Class::DBI ã®ããã«) ãã® O/R ããããå©ç¨ããå®éã®ãã¼ã¿ãã¼ã¹ã«ãã¤ã³ãããã¯ã©ã¹ãç¨æããããã script ã¿ã°ã«ããå¤é¨å¼åºãã§ã¤ã³ãã¼ãã§ããããã«ããã¨ã
ããã¨ã
var id = 12345; // primary key var employee = Employee.retrieve(id); employee.name; employee.age; ...
ã¿ãããªãã¨ã JavaScript ã§ã§ããããã«ãªã£ã¦ã¨ã¬ã¬ã³ããããªãããããã¾ããä¾ã«ãã£ã¦è¨ãæãè¡ãã¯é£ããªãã ããã©ãã