php_1
echo "<td> <a href='?fce=edit'> edit </a> </td>";
su - cd /var/www/html mkdir pokus chown jmeno pokus ll yum install httpd mysql mysql-server php php-mysqlnd phpMyAdmin apachectl start systemctl start mariadb.service
cp ~/Downloads/db-example.txt /var/www/html/pokus/db-example.php mysql -u root create database mydb; use mydb; create table colors (name varchar(80), red int, green int, blue int); insert into colors values ("blue", 0, 0, 255); select * from colors; describe colors; CREATE USER 'uzivatel'@'localhost' IDENTIFIED BY 'heslo'; GRANT ALL ON mydb.* TO 'uzivatel'@'localhost';
podivat se na http://localhost/pokus
soubor /var/www/html/pokus/priklad.php
<html> <head> <title> DB Example </title> <style type="text/css"> table, td, th { background-color: #eaf2ff; padding: 2px 15px 2px 15px; border-collapse:collapse; } th { background-color: #95B8E7; } .error { margin: 0.5em auto 0.5em auto; padding: 15px 10px 15px 55px; width: 450px; color: #ff0000; background: #fff0f0; border: 1px solid #ffcccc; } .note { margin: 0.5em auto 0.5em auto; padding: 15px 10px 15px 55px; width: 450px; background: #fffddf; border: 1px solid #ffcc00; } </style> </head> <body> <?php // phpinfo(); /******************************* FUNCTIONS ********************************/ function err ($msg) { echo '<div class="error">', "\n"; echo "Error: $msg \n"; echo '</div>', "\n"; exit; } function note ($msg) { echo '<div class="note">', "\n"; echo "Note: $msg \n"; echo '</div>', "\n"; } /* quote string */ function sql_str ($value) { return "'" . MySQL_Escape_String ($value) . "'"; } function html_str ($value) { return htmlspecialchars ($value); } /* parameters and session variables */ function param ($param_name) { if (isset ($_POST[$param_name])) { $value = $_POST[$param_name]; } else if (isset ($_GET[$param_name])) { $value = $_GET[$param_name]; } else { $value = ""; } // echo "$param_name: ", $value, '<br>', "\n"; return trim ($value); } /* database parameters */ $db_host = "localhost"; $db_user = "uzivatel"; $db_password = "heslo"; $database = "mydb"; /* database connection */ $connection = MySQL_Connect ($db_host, $db_user, $db_password) or Err (MySQL_Error()); MySQL_Select_Db($database) or Err (MySQL_Error()); /* actions */ ?> <a href="?fce=list"> list </a> <a href="?fce=abc"> abc </a> <br> <?php $fce = param ("fce"); if ($fce == "" or $fce == "list") { $cmd = "SELECT * FROM colors"; $results = MySQL_Query ($cmd) or Err (MySQL_Error()); echo "<table border=1>"; while ($data = MySQL_Fetch_Array ($results)) { echo "<tr> "; for ($k = 0; $k < 4; $k++) { $value = $data [$k]; echo "<td> $value </td>"; } echo "</tr> "; echo "<td> <a href='?fce=edit'> edit </a> </td>"; } echo "</table> "; } if ($fce == "edit") { echo "Edit"; } ?> <?php
php_1.txt · Last modified: 2014/04/24 12:25 by 127.0.0.1