PHP : Working with Resultsets. Last class  Open a connection to the MySQL server.  Specify the database  Issue queries (no updates at this stage) 

Slides:



Advertisements
Similar presentations
PHP: Date() Function The PHP date() function formats a timestamp to a more readable date and time.
Advertisements

PHP SQL. Connection code:- mysql_connect("server", "username", "password"); Connect to the Database Server with the authorised user and password. Eg $connect.
Widhy Hayuhardhika NP, S.Kom. Overview of database structure Connecting to MySQL database Selecting the database to use Using the require_once statement.
PHP and MySQL Database. Connecting to MySQL Note: you need to make sure that you have MySQL software properly installed on your computer before you attempt.
Faculty of Sciences and Social Sciences HOPE PHP & MySQL Stewart Blakeway FML 213
© Anselm SpoerriInfo + Web Tech Course Information Technologies Info + Web Tech Course Anselm Spoerri PhD (MIT) Rutgers University
Objectives Connect to MySQL from PHP
MySQL and PHP By Trevor Adams.
1 CS428 Web Engineering Lecture 23 MySQL Basics (PHP - VI)
02/09/2015 Intro PHP & MySQL 1 Helen Hastie Room: EMB244 Material available on Vision (modified from slides by Monica Farrow) F27DB Introduction.
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.
© Yanbu University College YANBU UNIVERSITY COLLEGE Management Science Department © Yanbu University College Module 6:WEB SERVER AND SERVER SIDE SCRPTING,
INFM 603: Information Technology and Organizational Context Jimmy Lin The iSchool University of Maryland Thursday, October 18, 2012 Session 7: PHP.
Application Sketch home.htm delete.php updateform.php display.php insert.php insertform.htm update.php Data Base Hyperlink Information exchange with database.
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:
Advanced Database Management System Lab no. 11. SQL Commands (for MySQL) –Update –Replace –Delete.
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizard’s Guide to PHP by David Lash.
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)
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
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.
SQL pepper. Why SQL File I/O is a great deal of code Optimal file organization and indexing is critical and a great deal of code and theory implementation.
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.
MySQL and PHP 3 March 2006 Adina Crainiceanu IT420: Database Management and Organization.
SQL pepper. Why SQL File I/O is a great deal of code Optimal file organization and indexing is critical and a great deal of code and theory implementation.
PHP MySQL. SQL: Tables CREATE TABLE tablename { fieldname type(length) extra info,... } Extra info: –NULL (allows nulls in this field) –Not NULL (null.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
Lec_6 Manipulating MySQL Databases with PHP PHP Programming with MySQL.
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.
MySQL Databases & PHP Integration Using PHP to write data to, and retrieve data from, a MySQL database.
SYST Web Technologies SYST Web Technologies Databases & MySQL.
Week 7. Lecture 2 Functions, Arrays, PHP&MySQL. Function with More than one argument and a return statement For a function to return a value, the return.
Association of Computing Activities Computer Science and Engineering Indian Institute of Technology Kanpur.
Lecture 10 – MYSQL and PHP (Part 2)
Technology & Management Club Development Software Overview.
Database Access with PHP and MySQL CS356 Examples from Web Database Applications, by Hugh E. Williams & David Lane, O'Reilly, 2002.
PHP with MySQL 1.
PHP+MySQL Integration. Connecting to databases One of the most common tasks when working with dynamic webpages is connecting to a database which holds.
MySQL Database Connection
PHP - MySQL Connection 8 March 2006 Adina Crainiceanu IT420: Database Management and Organization.
Creating PHPs to Insert, Update, and Delete Data CS 320.
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.
1 DBS201: Introduction to Structure Query Language (SQL) Lecture 1.
THE WEBMASTERS: SENG + WAVERING.  On account of construction, we will be having class in room 1248 next week.
Module Review Basic SQL commands: Create Database, Create Table, Insert and Select 2. Connect an SQL Database to PHP 3. Execute SQL Commands in.
© Anselm Spoerri Web Design Information Visualization Course Prof. Anselm Spoerri
NMD202 Web Scripting Week5. What we will cover today PHP & MySQL Displaying Dynamic Pages Exercises Modifying Data PHP Exercises Assignment 1.
MySQL. Is a SQL (Structured Query Language) database server. Can be accessed using PHP with embedded SQL Queries Supports Large DB’s, 60,000 tables with.
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.
SQL pepper. Why SQL File I/O is a great deal of code Optimal file organization and indexing is critical and a great deal of code and theory implementation.
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizard’s Guide to PHP by David Lash.
Databases.
Session 4 PHP & MySQL.
Web Design and Development
Introduction to Web programming
PHP + MySQL Commands Refresher.
ISC440: Web Programming 2 Server-side Scripting PHP 3
Tutorial 6 PHP & MySQL Li Xu
Database Access with PHP and MySQL
Introduction to Web programming
Presentation transcript:

PHP : Working with Resultsets

Last class  Open a connection to the MySQL server.  Specify the database  Issue queries (no updates at this stage)  Display the results in the table form.  Flush memory  Close the connection.

Today’s class  Learn to create database, tables, attributes using mySQL  Embed PHP “type” code with HTML “type” code  Help and kick start your project in your SAD class  Help and kick start your project in this class  Good Luck coz you need LOTS OF IT!

Create Table  If you need help on data type definition

Obtaining the number of columns/attributes  In MySQL you would do the following: $query = " SELECT * FROM employee " ; $result = mysql_query($query);// need this to get resultSET if (mysql_error()) { die( " cannot processed select query " ); } $num = mysql_num_rows($result); // obtain the number of rows/rec $numFields = mysql_num_fields($result); //obtain the number of cols  To obtain the column/attribute names $name = mysql_field_name($result, $i); where $i is the column number.. going from 0 to ($numFields – 1)

Obtaining the number of columns/attributes  Obtaining the length of an attribute $attrLen = mysql_field_len($result, $i); where $i is the column number.. going from 0 to ($numFields – 1)  Obtaining the attribute type $attrType = mysql_field_type($result, $i); where $i is the column number.. going from 0 to ($numFields – 1)

More function  Obtain the tables within the database $tables = mysql_list_tables("test_alum"); $numTables = mysql_num_rows($tables); $tableName = mysql_tablename($tables, $k); will give you the table names where $k goes from 0 to ($numTables – 1)

More function – field names $fields = mysql_list_fields("test_alum", $tableName); // field result $numfields = mysql_num_fields($fields); //get the number of fields // Do a for loop here to get the attribute name for index 0 to ($numfields – 1) for (…. ){ $fieldInfo = mysql_fetch_field($fields); echo $fieldInfo->name; } Note: The mysql_fetch_field() command will get you the NEXT attribute property.

Other characteristics echo $fieldInfo->blob; echo $fieldInfo->max_length; echo $fieldInfo->not_null; echo $fieldInfo->numeric; echo $fieldInfo->primary_key; echo $fieldInfo->table; echo $fieldInfo->type; echo $fieldInfo->unique_key; echo $fieldInfo->unsigned; echo $fieldInfo->zerofill; echo $fieldInfo->multiple_key;

Exercises jex7.php, jex8.php combine with HTML coding. Use skeleton code  jex7.php: You are to show all the tables and for the test_alum database  jex8.php: You are to show the attributes for the “users” table. In particular, you have to show the name of attribute; the type of attribute; whether it is numeric (show T is it is numeric and F if it is not)

Skeleton code PHP CODE with HTML commands <?php //insert your PHP code inside here ?>