1 / 13

PHP +SQL 13 .

PHP +SQL 13. PHP + MySQL PHPMyAdmin Practice: Vote system. PHP +SQL 13. PHP + MySQL PHPMyAdmin Practice: Vote system. MVC = Model + View + Controller. The separation of the main layers, also one of the most important software development principle/pattern

waldo
Download Presentation

PHP +SQL 13 .

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. PHP+SQL13. PHP + MySQL PHPMyAdmin Practice: Vote system OE NIK, 2013

  2. PHP+SQL13. PHP + MySQL PHPMyAdmin Practice: Vote system OE NIK, 2013

  3. MVC = Model + View + Controller • The separation of the main layers, also one of the most important software development principle/pattern • PHP: very weak in the beginning, nowadays it is getting better and better (Symfony/CodeIgniter, Doctrine, APC/Memcached, Assetic) Display layer(HTML + template) Business logic layer(PHP) Data (resource) layer(ORM) OE NIK, 2013

  4. Accessing databases in PHP • The physical access of the database is done by database-server-dependent modules (MySQL, MSSQL, Oracle, Sybase, PostgreSQL, Firebird) • The physical communication of the SQL commands and the TCP communication are done using functions with different names and parameter syntax  alternative: DBX • ODBC: Access any standardized database server • PDO: PHP Data Objects (similar to Java DAO), MVC-like mapping, it connects the Model and the Control layers using SQL-independent methods  Doctrine is a lot better from the development side, but PDO is a lot faster ... We’ll skip this due to lack of OOP PHP. . . OE NIK, 2013

  5. PHP and MySQL • libmysqld vs mysqlnd: physical connection • ext-mysql / ext-mysqli: Direct connection to a MySQL server, possibility to send out SQL commands directly • mysql_*  old, only procedural, but: a little faster, more conventional, but deprecated – not suggestedmysqli_*  new, possibility to work with OO, supports prepared statements and the execution of multiple queries and transactions(we will use this one, but WITHOUT OOP  ) • When using them the procedural style, the mysql_* and the mysqli_* commands have different parameter order! OE NIK, 2013

  6. MySQL commands • $conn=mysqli_connect(servername,username,password,dbname); • $res=mysqli_query($conn, $query); • $num=mysqli_insert_id($conn); // INSERT • $num=mysqli_affected_rows($conn); // UPD, DEL, INS • $num=mysqli_num_rows($res); • $row=mysqli_fetch_assoc($res); Check the databases slides onhttp://users.nik.uni-obuda.hu/szabozs/ !!! OE NIK, 2013

  7. Important things • $str=mysqli_real_escape_string($conn, $input); (prepared statement would be better. Please note that addslashes() is not safe, magic_quotes_gpc is ALWAYS OFF!) • $str=mysqli_error($conn); • $obj=mysqli_fetch_object($res); • mysql_set_charset($conn, "utf8"); (no mysql_query("set names 'utf8' ", $conn); ) OE NIK, 2013

  8. PHP+SQL13. PHP + MySQL PHPMyAdmin Practice: Vote system OE NIK, 2013

  9. PHPMyAdmin OE NIK, 2013

  10. PHP+SQL13. PHP + MySQL PHPMyAdmin Practice: Vote system OE NIK, 2013

  11. To do • create database php;grant all privileges on php.* to phpuser@localhost identified by 'phppw'; • Create tables: questions (qu_id, qu_text) + choices (cho_id, cho_qu, cho_text, cho_num) • Insert some example questions and possible choices! • Actions: LISTQ, LISTC, VOTE, ADDQ, ADDC (+DELQ, DELC) • HTML files: Question-row, Choice-row, Add question form, Add choice form, Back link OE NIK, 2013

  12. OE NIK, 2013

  13. OE NIK, 2013

More Related