PHP-MySQL By Jonathan Foss. PHP and MySQL Server Web Browser Apache PHP file PHP MySQL Client Recall the PHP architecture PHP can communicate with a MySQL.
out of 10
Post on 24-Dec-2015
- Slide 1
- PHP-MySQL By Jonathan Foss
- Slide 2
- PHP and MySQL Server Web Browser Apache PHP file PHP MySQL Client Recall the PHP architecture PHP can communicate with a MySQL server (either local or external)
- Slide 3
- PHP and MySQL To start a connection use mysql_connect(): mysql_connect(localhost,root,password) or die(Error connecting to mysql); Then select a database using mysql_select_db() mysql_select_db(mydatabase); To perform a query use mysql_query(): $query = SELECT id, email FROM users where name=\Jonny\; $res = mysql_query($query);
- Slide 4
- MySQL Results mysql_query() returns results in a result structure $query = SELECT id, email FROM users where name=\Jonny\; $res = mysql_query($query); Need to fetch rows from the result before use We can use either mysql_fetch_row() or mysql_fetch_assoc() $row = mysql_fetch_row($res); $row = mysql_fetch_assoc($res); $row = 1 $row = email@example.com $row = 1 $row = firstname.lastname@example.org $row[id] = 1 $row[email] = email@example.com $row[id] = 1 $row[email] = firstname.lastname@example.org
- Slide 5
- MySQL Security Issues Many security issues inherited from external sources Database security particularly important when reading user input SQL Injection attacks common attacks with PHP $res = mysql_query("SELECT userid FROM teacher where name=\$username\ AND password=\$password\"); But if $password is OR 1 = 1 The query becomes: SELECT userid FROM teacher where name=name AND password= OR 1 = 1 and the attacker will gain entry anyway! This is known as a SQL Injection attack!
- Slide 6
- Ways of securing PHP/SQL One of the easiest ways of preventing SQL Injection attacks is to escape the string first. This can be done using the mysql_real_escape_string function. This adds a \ to all quotes, so the parameter cant interfere with the query. $user = $_POST[username]; $password = $_POST[password]; $user = mysql_real_escape_string($user); $password = mysql_real_escape_string($password); $res = mysql_query(SELECT userid FROM users WHERE name=$user and password=$password); So OR 1 = 1 becomes \ OR \1\ = \ 1 And the password is treated as a single string rather than MySQL syntax
- Slide 7
- Securing PHP with MYSQLi A better way is to use MySQLi, which is an improved version of the PHP MySQL driver MySQLi is still fairly new, so some hosts may not provide it yet MySQLi allows MySQL querys to be paramaterized. The queries are prepared without the parameters, and then inserted using the bind_param function The first parameter of the bind_param describes the number and type of arguments. For instance si tells the function to expect two arguments: a string and an integer
- Slide 8
- PHP and MySQLi $user = me; $password=password; $query->prepare(SELECT userid from users where user=? and password=?); $query->bind_param(ss,$user,$password); $query->bind_result($userid); $query->execute(); $query->fetch(); User id is now stored in $userid
- Slide 9
- MD5 Security When storing passwords in a database, it is a good idea to hash them first This prevents people who may have access to the database from discovering the users password One of the most common hashes is MD5 (Message Digest) When user registers, the registration script takes an md5 hash of the password and stores the hash instead of the password When user logs in, the login script takes an md5 hash of the supplied password and checks it against the hash stored in the database If these two hashes are identical, the login script lets the person in
- Slide 10
- MD5 Example There are functions in both PHP and MySQL which calculate MD5 this example uses both to demonstrate both Registration script: $user = $_GET[user]; $password = $_GET[password]; mysql_query(INSERT INTO user (user, password) VALUES ($user, md5($password))) or die(Error: . mysql_error()); Login script: $user = $_GET[user]; $password = md5($_GET[password]); $res = SELECT id FROM user WHERE user=$user AND password=$password;
View more >
file upload and in php mysql - upload and in php mysql Download file upload and in php mysql upload and in php mysql Multi-file Upload with PHP, this includes verification for file extension and size, thus making ...
Advance PHP MySql Training PHP MySql Training Syllabus: Core Advance PHP MYSQL (Database) Object Oriented Programing in PHP Introduction and installation
FAMP FreeBSD/Apache/MySQL/PHP. Computer Center, CS, NCTU 2 Outline Introduction Apache MySQL PHP Installation and Administration MySQL Apache PHP.
APACHE+OPENSSL+CERTIFICATE+PHP+MYSQL+HTACCESS WEB ... OPENSSL+CERTIFICATE+PHP+MYSQL+HTACCESS WEB DIRECTORY+SQUID…
PHP & MySQL - ?· PHP & MySQL. Mode: Classroom Duration: 40 hours Course Outline PHP ─ Introduction.…
PHP MySQL Course Details - Besant MySQL Course Details By Besant Technologies Course Name PHP MySQL Category Scripting Language Web Development Venue Besant Technologies ... PHP MySQL Training Outline Introduction of Web PHP What is PHP? The history of PHP Why choose PHP? Installation overview ... CRUD in MySQL Populating a MySQL
W3Schools PHP/MySQL Database ?· Assignment W3Schools PHP/MySQL Database Tutorial Both PHP and MySQL…