Use PHP and JSP to connect with PHP and JSP in Win2000

xiaoxiao2021-03-06  37

Use PHP and JSP to connect with PHP and JSP in Win2000

-------------------------------------------------- ------------------------------ First, before reading this document, your Win2000 should have installed apache, JDK, Tomcat, PHP, MySQL. In this document, we don't prepare too much explanation for PHP, MySQL, JSP, we will assume that you have roughly master PHP, MySQL, JSP. We only explore the method of connecting MySQL using PHP and JSP under Win2000. Second, Mysql's pre-preparatory mysql installed before we installed the system initial root users. In this article, we are not prepared to continue to use root users, although we work in a test environment, but developing a good habit is crucial, because we will face it in the future will be a fully open Internet. As in most cases, the abuse of root users in MySQL may also cause mysql crash. The initial situation after mysql installation is a bit weird, to correctly increase the user and set up user permissions, we must clean up the table USER and DB in the MySQL library. First, enter the c: / mysql / bin directory in the command line mode, enter mysql directly, you will enter the MySQL client program mysql (below, we use mysql refer to MySQL client program, and in other occasions, we Mysql will be used. Enter: Show Databases after "MySQL>" prompt; you will see the initial state, there are two databases under MySQL: MySQL and Test, the Test Library is not used by us, and it will confuse the audio, so we You may wish to delete it: DROP DATABASE TEST; related users and their permissions save in the MySQL database, where the key is the DB table and user table, now we can clear the DB table first: use mysql; delete from DB; then we are for User The library is cleaned and refreshed: delete from user where user = '' or host = 'localhost'; flush privileges; now, quit MySQL with Quit. Now, you will not be able to enter Mysql directly into MySQL (that kind of situation does not require user authentication into mysql). You can only enter mysql -u root -p. If you have a password for the root user, you will be prompted to enter your password. If you haven't set it yet, press the Enter key directly to enter mysql. There is a terrible situation that there is no password, you'd better exit the client program with our method we describe in the installation of MySQL in WIN2000 to set a password after root and enter mysql. We create a new database for use: create database my_test; create a data table in this library: use my_test; create table my_test_table (test_column char (20) not null; In this table: Insert My_Test_Table VALUES ('Hello, I'm MySQL!'); Now we use the grant command to create a new user yzysy, which only has SELECT, UPDATE, INSERT, and DELETE permission to my_test.

The user's password is also YZYSY: GRANT SELECT, UPDATE, INSERT, DELETE ON MY_TEST. * To yzysy Identified by 'yzysy'; see the MYSQL User Manual for a detailed description of the GRANT command. Third, PHP connection MySQLPHP connection mysql is very simple, we don't need to make any settings. Create a new file mysql.php: PHP connection mysql! </ Title> </ head> <body> <$ dbcnx = mysql_connect ("localhost" , "yzysy", "yzysy"); mysql_select_db ("my_test"); $ result = mysql_query ("Select * from my_test_table", $ dbcnx); while ($ row = mysql_fetch_Array ($ result) Echo ("<p> <h1> "$ row [" test_column "]." </ h1> </ p> ");?> </ body> </ html> where mysql_connect () is used to connect the database server, mysql_select_db () To select a job database, mysql_query () is used to perform SQL queries, and mysql_fetch_array () is used to get the result set of SELECT. Now, open your browser, enter http://localhost/mysql.php in the address bar, you should see the "Hello, I'm MySQL!" Of the black body.</p> <p>Fourth, JSP connection MySQL JSP connection MySQL is a bit more complicated. First you have to download mm.mysql.jdbc-1.2c.tar.gz from http://www.mysql.com/downloads/contrib/mm.mysql.jdbc-1.2c.gz, then decompress it to the local In a directory of the hard disk (we use C: /MM.Mysql.jdbc-1.2c. Then add C: /mm.mysql.jdbc-1.2c at the last addition of the ClassPath system variable; (here / should be counterclockwise) Bar) Create a JavaBean called dbconn.java, build a mysqltest directory under Tomcat / WebApps / Examples / WEB-INF / CLASSES, save the file in this directory, dbconn.java is used to package the database link Operation. DBConn.java is as follows: package mysqltest; import java.sql. *; Public class dbconn {string dbdriver = "org.gjt.mm.mysql.driver"; string connStr = "JDBC: mysql: // localhost / my_test "; String MyUser =" yzysy "; String MyPassword =" yzysy "; Connection conn = null; ResultSet rs = null; public dBconn () {try {Class.forName (dBDriver);} catch (java.lang.ClassNotFoundException e ) {System.err.println ("dbconn ():" E.GetMessage ());}}} public resultSet ExecuteQuery (String SQL) {RS = NULL; try {conn = drivermanager.getConnection (Connstr, Myuser, Mypassword) Statement Stmt = conn.createstatement (); rs = stmt.executeQuery (SQL);} catch (sqlexception ex) {system.err.println ("Aq.executeQuery:" ex.getMessage ());} Return RS; }} We noticed that this program is only string dbdriver = "org.gjt.mm.mysql.driver"; string connStr = "jdbc: mysql: // localhost / my_test"; features with MySQL, the rest of the program There is no difference from other JDBC applications. Compile DBConn.java to form a corresponding Class file with JDK's Javac command. Built a mysqltest.jsp file in Tomcat's / WebApps / Examples / JSP directory.</p> <p>The content is as follows: <% @ Page ContentType = "text / html; charset = GB2312"%> <html> <head> <title> jsp connection mysql! </ Title> </ head> <body> <% @ Page Language = "Java" import = "java.sql. *"%> <jsp: usebean id = "dbconn1" scope = "page" class = "mysqltest.dbconn" /> <% resultset = dbconn1.executeQuery ("SELECT * From my_test_table "); while (rs.next ()) {out.print (" <h1> " rs.getstring (" test_column ") " </ h1> ");} rs.close ();%> </ body> </ html> here, you have seen any mysql traces. Now enter http: //localhost/examples/jsp/mysqltest.jsp in the address bar of the browser, you should be able to see the "Hello, I'm mysql!" Of the black body. 5. Conclusion Now, your Win2000 has successfully built a zero-cost web server. However, I personally believe that it can only be used as a development environment in Win2000, and I really want to use, and use Linux to get more performance and security guarantees.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-61861.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="61861" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.051</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = '35Xa6R_2FG60YByVHTkMjstc3NfmgT_2BvCK463Q828ljGFG3k8UGRRp4yTseIdbU5VXzNW3Ovczp1rg_2B0jIT14rOQ_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>