PHP MySQL. SQL: Tables CREATE TABLE tablename { fieldname type(length) extra info,... } Extra info: –NULL (allows nulls in this field) –Not NULL (null.

Slides:



Advertisements
Similar presentations
PHP II Interacting with Database Data. The whole idea of a database-driven website is to enable the content of the site to reside in a database, and to.
Advertisements

PHP SQL. Connection code:- mysql_connect("server", "username", "password"); Connect to the Database Server with the authorised user and password. Eg $connect.
Manipulating MySQL Databases with PHP. PHP and mySQL2 Objectives Connect to MySQL from PHP Learn how to handle MySQL errors Execute SQL statements with.
Objectives Connect to MySQL from PHP
Lecture 4: Introduction to PHP 3 PHP & MySQL
MySQL and PHP By Trevor Adams.
Intermediate PHP & MySQL
PHP and MySQL Web Development tMyn1 PHP and MySQL Web Development When you install PHP, you can select from a number of extensions. The MySQL support in.
Website Development Working with MySQL. What you will achieve today! Connecting to mySql Creating tables in mySql Saving data on a server using mySql.
DAT702.  Standard Query Language  Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.
1 CS428 Web Engineering Lecture 23 MySQL Basics (PHP - VI)
SQL | PHP Tutorial at 8am. god, it’s early.. SQL intro There are many different versions of SQL available for usage. Oracle MySQL SQLite DB2 Mimer The.
What is MySQL? MySQL is a database. The data in MySQL is stored in database objects called tables. A table is a collections of related data entries and.
PHP1-1 PHP & SQL Xingquan (Hill) Zhu
1 Pertemuan 13 PHP-MySQL Last Updated: 15 th May 2010 By M. Arief
© Yanbu University College YANBU UNIVERSITY COLLEGE Management Science Department © Yanbu University College Module 6:WEB SERVER AND SERVER SIDE SCRPTING,
1 Chapter 8 – Working with Databases spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science and Technology.
Slide 8-1 CHAPTER 8 Using Databases with PHP Scripts: Using MySQL Database with PHP.
MySQL in PHP – Page 1 of 17CSCI 2910 – Client/Server-Side Programming CSCI 2910 Client/Server-Side Programming Topic: MySQL in PHP Reading: Williams &
INTERNET APPLICATION DEVELOPMENT For More visit:
MySQL + PHP.  Introduction Before you actually start building your database scripts, you must have a database to place information into and read it from.
Advanced Database Management System Lab no. 11. SQL Commands (for MySQL) –Update –Replace –Delete.
PHP MySQL Introduction
PHP – MySQL Extensions. Table used in most examples CREATE TABLE product ( rowID INT NOT NULL AUTO_INCREMENT, productid VARCHAR(8) NOT NULL, name VARCHAR(25)
In the next lectures you will learn  What is SQL  How to access mySQL database  How to create a basic mySQL database  How to use some basic queries.
INTERNET APPLICATION DEVELOPMENT PRACTICAL ON CONNECTING TO MYSQL.
MySQL + PHP.  Introduction Before you actually start building your database scripts, you must have a database to place information into and read it from.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
 Mysql – popular open-source database management system  PHP usually works with Mysql for web- based database applications  LAMP applications—Web-based.
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
Introduction to MySQL Lab no. 10 Advance Database Management System.
PHP MySQL Introduction. MySQL is the most popular open-source database system. What is MySQL? MySQL is a database. The data in MySQL is stored in database.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
Chapter 6 PHP Interacts with Mysql Database. Introduction In PHP, there is no consolidated interface. Instead, a set of library functions are provided.
MySQL PHP Web Technology. Logging in to Command Line Start -> Programs -> AppServ -> MySQL Command Line Client Enter Password, then you’ll be working.
SYST Web Technologies SYST Web Technologies Databases & MySQL.
1. Connecting database from PHP 2. Sending query 3. Fetching data 4. Persistent connections 5. Best practices.
Lecture 10 – MYSQL and PHP (Part 2)
MySQL Database Connection
Web-Based Database Programming with PHP. Dept. of Computing Science, University of Aberdeen2 In this lecture you will learn PHP Basics PHP functions –To.
Pengantar Teknologi Internet W14: Server Scripting & Database.
CISC 3140 (CIS 20.2) Design & Implementation of Software Application II Instructor : M. Meyer Address: Course Page:
Intro to DatabasesClass 4 SQL REVIEW To talk to the database, you have to use SQL SQL is used by many databases, not just MySQL. SQL stands for Structured.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP & MySQL.
PHP Database connectivity Connecting with RDBMS and editing, adding, and deleting databases therein are all done through PHP functions.
PHP Database Processing CIS 1715 Web Technologies.
PHP and Mysql Database. PHP and Database Mysql – popular open-source database management system PHP usually works with Mysql for web-based database applications.
Module Review Basic SQL commands: Create Database, Create Table, Insert and Select 2. Connect an SQL Database to PHP 3. Execute SQL Commands in.
NMD202 Web Scripting Week5. What we will cover today PHP & MySQL Displaying Dynamic Pages Exercises Modifying Data PHP Exercises Assignment 1.
Accessing mySQL relational database. MySQL database.  Today, we will attempt and open a connection to the MySQL server.  We need to specify the database.
Chapter 8 Manipulating MySQL Databases with PHP PHP Programming with MySQL 2 nd Edition.
CHAPTER 10 PHP MySQL Database
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizard’s Guide to PHP by David Lash.
1 PHP and MySQL Web Development When you install PHP, you can select from a number of extensions. The MySQL support in PHP consists of a number of functions.
PHP & MY SQL Instructor: Monireh H. Sayadnavard 1.
Web Systems & Technologies
The Web Wizard’s Guide to PHP by David Lash
Tried my best to simplify it for you!
Unix System Administration
Chapter 19 PHP Part III Credits: Parts of the slides are based on slides created by textbook authors, P.J. Deitel and H. M. Deitel by Prentice Hall ©
Introduction to Web programming
MySQL tutorial.
PHP and MySQL.
PHP: Database connection
Web Programming– UFCFB Lecture
MySQL Database System Installation Overview SQL summary
Introduction to Web programming
Presentation transcript:

PHP MySQL

SQL: Tables CREATE TABLE tablename { fieldname type(length) extra info,... } Extra info: –NULL (allows nulls in this field) –Not NULL (null is not allowed value for this field) –AUTO_INCREMENT (value=biggest value in this field among existing +1

SQL: Tables Field TypeDescription TINYINTSmall Integer Number SMALLINTSmall Integer Number MEDIUMINTInteger Number INTInteger Number VARCHARText (maximum 255 characters) TEXTText

SQL: Tables: Example CREATE TABLE birthdays ( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), Name VARCHAR(30), Birthday VARCHAR(7) )

SQL Select * or list of fields From table_name [Where conditions] Select * from birthdays Select Name from birthdays where id>12 And birthday=‘June4’ Delete from table_name [Where conditions] Delete from birthdays where name=‘Peggy’

SQL Insert Into table_name [(fields list)] VALUES(fields values) INSERT INTO birthdays (name, birthday) VALUES ('Peggy', 'June4') Update table_name Set [field=value,...] [Where conditions] UPDATE birthdays SET birthday=‘ ’ WHERE name='Peggy'

PHP/MySQL: Connection resource mysql_connect ( [string server [, string username [, string password]]]) Open a connection to a MySQL Server. If you would like to use more than one connection then use returned parameter to identify connection for later mysql functions calls. bool mysql_select_db ( string database_name [, link_identifier]) sets the current active database on the server that's associated with the specified link identifier. If no link identifier is specified, the last opened link is assumed. If no link is open, the function will try to establish a link as if mysql_connect() was called without arguments, and use it. bool mysql_close ( [link_identifier]) Close connection that's associated with the specified link identifier. If link_identifier isn't specified, the last opened link is used.

Example <? $user="username"; $password="password"; $database="database"; or die( "Unable to select database");... mysql_close(); ?>

Example 2 <? $link = mysql_connect( "localhost", $_POST['username'], $_POST['password']) or die ("Connect Error: ".mysql_error()); print "Successfully connected.\n"; mysql_close($link); ?>

PHP/MySQL: Working with resource mysql_query(string $query[, link_identifier]) sends a query to the currently active database on the server that's associated with the specified link identifier. mixed mysql_result ( resource result, int row [, mixed field]) Returns the contents of one cell from a MySQL result set. $variable=mysql_result($result,$i,"fieldname"); $variable=mysql_result($result,2,0); //Returns a value of the first column value of the third record int mysql_num_rows ( resource result) Returns the number of rows in a result set. PS:This command is only valid for SELECT statements. To retrieve the number of rows affected by a INSERT, UPDATE or DELETE query, use mysql_affected_rows(). mysql_affected_rows()

Example <? $username=“u"; $password=“p"; $database=“db"; or die( "Unable to select database"); $query="SELECT * FROM contacts"; $result=mysql_query($query); $num=mysql_num_rows($result); mysql_close(); echo " Database Output "; $i=0; while ($i < $num) { $phone=mysql_result($result,$i,"phone"); $ =mysql_result($result,$i," "); $web=mysql_result($result,$i,"web"); echo "Phone: $phone Mobile: $mobile $ Web: $web "; ++$i; } ?>

Example (Title Here) <?php $db="mydatabase"; $link = mysql_connect("localhost"); if (! $link) die("Couldn't connect to MySQL"); mysql_select_db($db, $link) or die("Couldn't open $db: ".mysql_error()); $result = mysql_query("SELECT * FROM birthdays") or die("SELECT Error: ".mysql_error()); $num_rows = mysql_num_rows($result); print "There are $num_rows records. "; print " \n"; while ($get_info = mysql_fetch_row($result)){ print " \n"; foreach ($get_info as $field) print "\t $field \n"; print " \n"; } print " \n"; mysql_close($link); ?>