DEV Training Sahana Developer Training
DEV Training PHP
DEV Training PHP-Overview PHP Hypertext Preprocessor Is a Scripting language for web development Is Platform independent Windows, Linux, Mac... Web browser Version PHP 5,6 Is an Interpreted language
DEV Training PHP-Setup Windows WAMP,XAMPP Linux Apache module Apt-get install php5 Mac?
DEV Training PHP-Writing Code Write code in some text editor or dev environment Store files with.php extension example_file.php Store PHP file web server root folder
DEV Training PHP-Check <?php phpinfo(); ?>
DEV Training PHP-Hello Alpha Centauri <?php echo “Hello Alpha Centauri”; ?> Hello Alpha Centauri
DEV Training PHP-Embedding PHP
DEV Training Variables/Expressions <?php $var = 1; $var2 = “this_is_a_string”; $var3 = 1.32; $var4 = $var + 1; ?>
DEV Training Arrays <?php $foo[1] = 1; $foo[2] = 2; $bar[1][2] = 3; ?>
DEV Training Functions <?php phpinfo(); foo(); $len = strlen($foo); ?>
DEV Training Control Structures <?php while($foo>1) {... } if($test==true){.... } ?>
DEV Training Output <?php echo $foo; printf(".2f",$price); ?>
DEV Training Object Orientation <?php class Cart { var $items; function add_item($artnr, $num) { $this->items[$artnr] += $num; } ?>
DEV Training MySQL
DEV Training F/OSS Database server Simple Relational Database Works well with PHP
DEV Training MySQL::SQL Command line Windows: Run->cmd->... Linux: Terminal/Shell mysql -u -p mysql -u root -p sahana_db GUI PHPMyadmin MySQLCC MySQLAdmin
DEV Training Server - localhost Database - test Table -... Username - root Password - ?
DEV Training <?php $conn = mysql_connect('localhost'); echo $conn; ?> <?php $conn = mysql_pconnect('localhost'); echo $conn; ?>
DEV Training SQL Structured Query Language INSERT INSERT INTO (col1,col2) VALUES (val1,val2); SELECT SELECT * FROM ; SELECT name,address FROM people_table WHERE location='Manilla';
DEV Training <?php // Make a MySQL Connection mysql_connect("localhost", "admin", "1admin") or die(mysql_error()); mysql_select_db("test") or die(mysql_error()); // Create a MySQL table in the selected database mysql_query("CREATE TABLE example( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), name VARCHAR(30), age INT)") or die(mysql_error()); echo "Table Created!"; ?>
DEV Training <?php mysql_pconnect("db.server.com","username","password"); mysql_select_db("products"); $result = mysql_query("SELECT * FROM details"); if ($result) { echo " \n"; echo " Name Description \n"; while ($a = mysql_fetch_array($result)) { echo " $a[name] ", " $a[descr] "; } echo " "; } else { echo " Nothing to see here."; } ?>