Bài giảng lập trình web chương 4 ths nguyễn minh vi

77 316 0
Bài giảng lập trình web   chương 4   ths  nguyễn minh vi

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

PHP - MySQL GIỚI THIỆU ThS Nguyễn Minh Vi BM Tin học – ĐH An Giang PHP    PHP (Hypertext Preprocessor) ngôn ngữ script phía server PHP hỗ trợ nhiều sở liệu (MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, ) Tập tin PHP:  chứa text, thẻ HTML đoạn script; kết trả trình duyệt HTML  có phần mở rộng ".php" MySQL MySQL hệ quản trị sở liệu phía server  MySQL hỗ trợ SQL chuẩn  PHP-MySQL PHP kết hợp với MySQL chạy nhiều platform khác  PHP MySQL hoàn toàn miễn phí  Một số hệ thống mã nguồn mở phổ biến:   Quản trị nội dung, cổng thông tin: Joomla, Drupal, PHP-Nuke, …  Diễn đàn: phpBB, MyBB, SMF, …  Thương mại điện tử: ZenCart, OpenCart, …  Đào tạo trực tuyến: Moodle, …  Blog: Wordpress, … PHP-MySQL  Để bắt đầu với PHP MySQL, ta cần chuẩn bị:  Cài đặt web server (IIS, Apache, …)  Cài PHP  Cài MySQL  Download:  Apache: httpd.apache.org/download.cgi  PHP: www.php.net/downloads.php  MySQL: www.mysql.com/downloads/index.html  Đơn giản hơn, download phần mềm WAMP, Vertrigo, XAMPP… PHP PHP Hypertext Preprocessor ThS Nguyễn Minh Vi BM Tin học – ĐH An Giang PHP        Cú pháp Biến Kiểu liệu Toán tử Cấu trúc điều khiển Hàm Ví dụ xử lý form PHP        Cú pháp Biến Kiểu liệu Toán tử Cấu trúc điều khiển Hàm Ví dụ xử lý form Cú pháp  Một khối lệnh PHP đặt nơi trang web   Mỗi câu lệnh kết thúc dấu ; Chú thích  // dòng  /* nhiều dòng */  Cú pháp gần giống C++, Perl Ví dụ Ex Retrieve a cookie value Use the PHP $_COOKIE variable  Ex:  Delete a cookie  Assure that the expiration date is in the past PHP Session ThS Nguyễn Minh Vi BM Tin học – ĐH An Giang Session   A PHP session allowing you to store user information on the server for later use, session information is temporary and will be deleted after the user has left the website Sessions work by creating a unique id (UID) for each visitor and store variables based on this UID Starting a PHP Session  The session_start() function  place before the tag Storing a Session Variable  Use the PHP $_SESSION variable Destroying a Session  The unset() function is used to free the specified session variable  The session_destroy() function is used to destroy the session completely PHP Email ThS Nguyễn Minh Vi BM Tin học – ĐH An Giang mail() function  Syntax mail(to,subject,message,headers,parameters)  Parameters  to: (required) specifies the receiver / receivers of the email  subject: (required) specifies the subject of the email  message: (required) defines the message to be sent mail() function  Parameters (cont.)  headers (optional) specifies additional headers, like From, Cc, and Bcc The additional headers should be separated with a CRLF (\r\n)  parameters (optional) specifies an additional parameter to the sendmail program Example more  To send mail to multiple recipients, using comma $to = 'bibi@gmail.com' ', '; $to = 'bobo@gmail.com';  To send HTML mail, set the Content-type header $headers = 'Content-type: text/html; charset=utf-8' Configuration (php.ini) Name SMTP smtp_port sendmail_from sendmail_path Default "localhost" "25" NULL NULL Configuration  SMTP  DNS name or IP address of the SMTP server PHP should use for mail sent with the mail() function  smtp_port  Number of the port to connect to the server specified with the SMTP setting when sending mail with mail(); defaults to 25 (available since PHP 4.3.0) [...]... So sánh (Comparison)  Logic (Logical)  Toán tử  Số học: Operator Description Example Result + Addition x=2 x+2 4 - Subtraction x=2 5-x 3 * Multiplication x =4 x*5 20 / Division 15/5 5/2 3 2.5 % Modulus (division remainder) 5%2 10%8 10%2 1 2 0 ++ Increment x=5 x++ x=6 Decrement x=5 x x =4 Toán tử  Gán: Operator = += -= *= /= %= Example x=y x+=y x-=y x*=y x/=y x%=y Is The Same As x=y x=x+y x=x-y x=x*y... value; Biến  Ví dụ: $myString  $4me  $_4you  Biến đặc biệt $GLOBALS  $_COOKIE  $_GET  $_POST  $_REQUEST  $_GET    Biến $_GET chứa một mảng tên biến và giá trị được gởi bởi phương thức HTTP GET Biến $_GET dùng để lấy giá trị từ form với phương thức truyền dữ liệu method="get" Thông tin gửi từ form với phương thức GET được hiển thị trên thanh địa chỉ của trình duyệt, khối lượng dữ liệu gửi... phương thức truyền dữ liệu là GET hay POST  Phạm vi biến Biến trong một hàm thì là biến cục bộ đối với hàm đó  Biến khai báo trong một khối lệnh thì khả dụng trong suốt khối lệnh đó, nhưng không khả dụng trong hàm  Biến dùng trong một hàm mà khai báo là toàn cục thì nó tham chiếu đến biến toàn cục cùng tên   dùng $GLOBALS hoặc từ khóa global Phạm vi biến  Ví dụ Array Mảng chứa một hoặc ... ?>. You are years old Xử lý form Minh 22 MySQL ThS Nguyễn Minh Vi BM Tin học – ĐH An Giang Kết nối đến CSDL MySQL  Cú pháp: mysql_connect( servername,... Subtraction x=2 5-x * Multiplication x =4 x*5 20 / Division 15/5 5/2 2.5 % Modulus (division remainder) 5%2 10%8 10%2 ++ Increment x=5 x++ x=6 Decrement x=5 x x =4 Toán tử  Gán: Operator = += -=...  Đơn giản hơn, download phần mềm WAMP, Vertrigo, XAMPP… PHP PHP Hypertext Preprocessor ThS Nguyễn Minh Vi BM Tin học – ĐH An Giang PHP        Cú pháp Biến Kiểu liệu Toán tử Cấu trúc điều

Ngày đăng: 03/12/2015, 18:17

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan