1 / 8

Assignment help PHP + MySQL crash course

Assignment help PHP + MySQL crash course. Gyozo Gidofalvi. Assignment. Implement a movie database with a web front-end using the Linux-Apache-MySQL-PHP, or LAMP, Web development framework To be completed in groups (3-5) Deploy solution See me in the lab to get a MySQL account for your group

Download Presentation

Assignment help PHP + MySQL crash course

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Assignment help PHP + MySQL crash course Gyozo Gidofalvi

  2. Assignment • Implement a movie database with a web front-end using the Linux-Apache-MySQL-PHP, or LAMP, Web development framework • To be completed in groups (3-5) • Deploy solution • See me in the lab to get a MySQL account for your group • Demo your solution during the scheduled labs Gyozo Gidofalvi

  3. Connecting to MySQL from PHP <? $link = mysql_connect($hostname, $username, $password) or die("Could not open connection to database"); ?> • Now the variable $link contains the information for your connection to MySQL. You can disconnect using: <? mysql_close($link) or die("Could not close connection to database"); ?> Gyozo Gidofalvi

  4. Select a database, issue queries • Once you have connected successfully, you should select the database you will use. Then you can issue queries to the database. <? mysql_select_db(“ecomXXXX", $link) or die("Could not select database"); $result = mysql_query("select * from some_table") or die("Could not issue MySQL query"); ?> • Now the variable $result will be used to reference the query we just made. Gyozo Gidofalvi

  5. Array handling in PHP • In PHP, arrays are associative. Any number or string can be used to index an array. <? $array["hello"] = 3; $array[5] = "how are you?"; while (list($column, $value) = each($array)) { print("$column = $value\n"); } reset($array); ?> • This example would print: hello = 3 5 = how are you? • The command reset($array) puts the array iterator back to the beginning of the array. Gyozo Gidofalvi

  6. Getting the results from a query • After issuing a query, you retrieve the results using the variable $result. <? if (mysql_num_rows($result) == 0) { print("No results matching your query<BR>\n"); } else { print("Here are the results:<BR>\n"); while ($row = mysql_fetch_row($result)) { while (list($colname, $value) = each($row)) { print("$value "); } print("<BR>\n"); } } ?> Gyozo Gidofalvi

  7. HTML forms and PHP variables • From an HTML page that had this form: <FORM ACTION="target.php" METHOD="GET"> <INPUT TYPE="TEXT" NAME="myvar"> <INPUT TYPE="TEXT" NAME="yourvar"> <INPUT TYPE="SUBMIT" NAME="submit"> </FORM> • The PHP script (target.php) will receive the variables from the form by the same name: <? print("you entered myvar = $_GET[myvar], yourvar = $_GET[yourvar]\n"); ?> Gyozo Gidofalvi

  8. Useful string stuff in PHP • Difference between single and double quotes: <? $name = "Joe"; print("hello, your name is $name\n"); print(‘hello, your name is $name\n’); ?> • Output:hello, your name is Joe hello, your name is $name • $trimmed = trim(" this string has whitespace ");removes leading and trailing whitespace • $encoded = urlencode("this is a non-encoded url string");changes the argument so that it will be part of a valid URL Gyozo Gidofalvi

More Related