50 likes | 190 Views
Intro to PHP and MySQL. ICS 215 Jan Stelovsky. PHP History. Rasmus Lerdorf 1995 Not an academic, consultant Goal dynamic web sites not doing the same thing over and over Solution Reusable code snippets HTML Templates. PHP Facts. Installed on 2.1 million web servers
E N D
Intro to PHP and MySQL ICS 215 Jan Stelovsky
PHP History • Rasmus Lerdorf 1995 • Not an academic, consultant • Goal • dynamic web sites • not doing the same thing over and over • Solution • Reusable code snippets • HTML Templates
PHP Facts • Installed on 2.1 million web servers • Used on 244 million websites • deployed on most web servers • as standalone shell on almost every operating system • Usage • server-side scripting language • also general-purpose programming language • web development • interpreted by a web server • PHP processor generates web page • PHP commands embedded directly in HTML source • similar to Ruby on Rails, • free • PHP License, like GNU General Public License (GPL)
Taste of PHP and MySQL <?php $dsn = 'mysql:host=localhost;dbname=app'; $user = 'root'; $password = 'secret'; $query = "SELECT vendor_name, invoice_no, invoice_tot FROM vendors INNER JOIN invoices ON vendors.vendor_id = invoices.vendor_id WHERE invoice_tot>= 500 ORDER BY vendor_name, invoice_totDESC"; try { $database = new PDO($dsn, $user, $password); } catch (PDOException $error) { echo $error->getMessage(); exit(); } $rows = $database->query($query); ?>
Taste of PHP and MySQL (cont) <!DOCTYPE html> <html lang="en"><head> <title>PHP & MySql Test</title> </head><body> <h1>Invoices with totals over 500:</h1> <?phpforeach ($rows as $row) : ?> <p> Vendor: <?php echo $row['vendor_name']; ?><br/> Invoice#: <?php echo $row['invoice_no']; ?><br/> Total: $<?php echo number_format($row['invoice_tot'], 2); ?> </p> <?phpendforeach; ?> </body></html>