Www.bzupages.com PHP Database connectivity Connecting with RDBMS and editing, adding, and deleting databases therein are all done through PHP functions.

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.
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.
Objectives Connect to MySQL from PHP
MySQL and PHP By Trevor Adams.
ADVM420- Class #4 Web Design with PHP and MySQL Adding and Listing from a MySQL Database.
Database Basics CS Why use a database?  powerful: can search it, filter data, combine data from multiple sources  fast: can search/filter a database.
1 CS428 Web Engineering Lecture 23 MySQL Basics (PHP - VI)
SJSU CS157B Dr. Lee1  2004 Jenny Mitchell Two Useful Tools You Can’t Live Without by Jenny Mitchell SJSU CS157B Section PHP and MySQL.
Application Development Description and exemplification of server-side scripting language for server connection, database selection, execution of SQL queries.
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
Deleting and Updating Records in MySQL using PHP Basharat Mahmood, Department of Computer Science,CIIT,Islamabad, Pakistan. 1.
© Yanbu University College YANBU UNIVERSITY COLLEGE Management Science Department © Yanbu University College Module 6:WEB SERVER AND SERVER SIDE SCRPTING,
Class 3 MySQL Robert Mudge Reference:
Application Sketch home.htm delete.php updateform.php display.php insert.php insertform.htm update.php Data Base Hyperlink Information exchange with database.
LIS651 lecture 7 PHP mySQL Thomas Krichel
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.
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.
INTERNET APPLICATION DEVELOPMENT PRACTICAL ON CONNECTING TO MYSQL.
Sys Prog & Scripting - HW Univ1 Systems Programming & Scripting Lecture 19: Database Support.
 Mysql – popular open-source database management system  PHP usually works with Mysql for web- based database applications  LAMP applications—Web-based.
NMED 3850 A Advanced Online Design January 26, 2010 V. Mahadevan.
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.
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.
SYST Web Technologies SYST Web Technologies Databases & MySQL.
PHP Part 2.
INTERNET APPLICATION DEVELOPMENT Practical on Sessions.
1. Connecting database from PHP 2. Sending query 3. Fetching data 4. Persistent connections 5. Best practices.
Lecture 10 – MYSQL and PHP (Part 2)
Database Access with PHP and MySQL CS356 Examples from Web Database Applications, by Hugh E. Williams & David Lane, O'Reilly, 2002.
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
Pengantar Teknologi Internet W14: Server Scripting & Database.
CHAPTER 9 PHP AND MYSQL. A POSSIBLE SITE CONFIGURATION Application Folder index.php includes (folder)header.phpfooter.phpstyle.cssmodel (folder)mysqli_connect.php.
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.
Creating PHPs to Insert, Update, and Delete Data CS 320.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP & MySQL.
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.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
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.
PHP Programming. Topics Database Handling (MySQL, MSSQL, ODBC)
PHP: MySQL. PHP Connect to MySQL PHP 5 and later can work with a MySQL database using: – MySQLi extension (the "i" stands for improved) – PDO (PHP Data.
Database MySQL Universitas Muhammadiyah Surakarta Yogiek Indra Kurniawan.
Chapter 8 Manipulating MySQL Databases with PHP PHP Programming with MySQL 2 nd Edition.
CHAPTER 10 PHP MySQL Database
OBJECTIVES Learn how to view data using SQL and PHP Learn how to add new data using SQL and PHP PHP+SQL: View and Adding,
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
Introduction to Web programming
MySQL tutorial.
PHP: Database Basic Selection FdSc Module 109
PHP: Database connection
Web Programming– UFCFB Lecture
PHP AND MYSQL.
Introduction to Web programming
Conection
Presentation transcript:

PHP Database connectivity Connecting with RDBMS and editing, adding, and deleting databases therein are all done through PHP functions Connect with MySQL RDBMS – mysql_connect($hostName, $userName, $password) or die("Unable to connect to host $hostName"); Connect with database – mysql_select_db($dbName, $con_var) or die("Unable to select database $dbName");

Connection Check Code $link = mysql_connect("localhost", “root", ""); if (!$link) { echo "Can't connect to localhost. The error is "; } Note the use of ! to express Boolean "not".

PHP Data Base Queries: Nearly all table interaction and management is done through queries: Mysql_query($query, $con) issues SQL statements Basic information searches – $SQL = "SELECT FirstName, LastName, DOB, Gender FROM Patients WHERE Gender = '$Gender‘; $Patients = mysql_query($SQL,$link) or die (“can execute query”); Editing, adding, and deleting records and tables – $SQL = "INSERT INTO Patients (FirstName, LastName) VALUES('$firstName', '$lastName')"; $Patients = mysql_query($SQL);

PHP Database Cleaning up: close the database connection, It requires the connection as an argument, so that it knows which connection to close. – mysql_close($link);

examining resulting rows mysql_fetch_array(result) returns an array that is the result row, or NULL if it the last result is reached. – Its results in an array that contains the columns requested both by number and by column name: while($columns=mysql_fetch_array($result)) { echo 'name: '.$columns['name']; echo 'first column: ‘.$columns[0]; }

mysql_num_rows() This command has the syntax mysql_select_db($result) – where the resource result is the result of a query. It returns the number of rows that are in the result. This is useful in announcing the number results before display of results.

Conf.php (Code Example) <php? // configuration parameters // database configuration $host = “localhost"; $user = “root"; $pass = “"; $db = “db_it"; ?>

Example Code include("conf.php"); $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); mysql_select_db($db, $connection) or die ("Unable to select database!"); $query = "INSERT INTO papers (title, authors, description, comment, super, bibtex, url, genre) VALUES ('$title', '$authors', '$description', '$comment', '$super','$bibtex','$url','$genre')"; $result = mysql_query($query, $connection) or die ("Error in query: $query. ". mysql_error()); // close database connection mysql_close($connection);

Example Code include("conf.php"); $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); mysql_select_db($db,$connection) or die ("Unable to select database!"); $query = "INSERT INTO papers (title, authors, description, comment, super, bibtex, url, genre) VALUES ('$title', '$authors', '$description', '$comment', '$super','$bibtex','$url','$genre')"; $result = mysql_query($query, $connection) or die ("Error in query: $query. ". mysql_error()); // close database connection mysql_close($connection);

Example Code include("conf.php"); $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db,$connection ) or die ("Unable to select database!"); // generate and execute query $query = "DELETE FROM papers WHERE id = '$id'"; $result = mysql_query($query) or die ("Error in query: $query. ". mysql_error()); // close database connection mysql_close($connection);