![]() ![]() Our script can tell when it is being run as a result of a submission of the form we just saw by checking for the presence of the $submitquery variable. ![]() So in addition to displaying the form, this one script also needs to process the form submission. I’ve also assigned an accesskey attribute to the submit button to allow it to be triggered with the keyboard: SQL Query:Īs for the tag that contains all these elements, it will be set to submit the form back to the same URL using the PHP variable $PHP_SELF as the action attribute: " method="POST"> For convenience, I’ve set the to select the text it contains whenever it gains focus (notice the onFocus attribute). The rest of the form is pretty straightforward - a and a submit button. We do that with the PHP function mysql_list_dbs, then we use a for loop to go through that list and use the mysql_db_name function to produce an in the list for each database: Target Database: Now, to generate the drop-down list in the form, we need to retrieve a list of the databases in the MySQL server. To generate that list, we’ll need a connection to the MySQL database server, so that’s what our script begins with: The only real convenience feature we’ve added to the interface is a drop-down list, to indicate the database that will be the target of the query. We’ll look at each component of the script separately, and I’ll provide the complete code at the end of the article, so focus on the code segment at hand, and we’ll see how it all fits together at the end. In this article, I’ll provide a convenient alternative - a Web-based MySQL command line! Written in PHP, this script will let you type SQL queries into a text field and view the results or, in the case of error, any error messages generated. To learn SQL, developers are often forced to install a MySQL server on their own computer just to have a command line to play with. The net result is that the MySQL command line is not available to users of most Web hosts. In Chapter 2 of my article series, Build your own Database Driven Website using PHP & MySQL, I focus on getting beginners comfortable with typing SQL queries on the MySQL command line.Ī common problem faced by people getting started with MySQL is that most Web hosts these days don’t provide shell access to the server, nor do they allow remote connections to their MySQL servers. One of the essential skills you must acquire to become proficient in the development of PHP/MySQL driven websites is a good understanding of Structured Query Language (SQL).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |