Working with PHP and Postgresql. pg_connect ( string $connection_string [, int $connect_type ] ) pg_connect() opens a connection to a PostgreSQL database.

Slides:



Advertisements
Similar presentations
LIS651 lecture 3 taming PHP Thomas Krichel
Advertisements

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.
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.
Part 2.  Arrays  Functions  Passing Variables in a URL  Passing variables with forms  Sessions.
Faculty of Sciences and Social Sciences HOPE PHP & MySQL Stewart Blakeway FML 213
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
MySQL and PHP By Trevor Adams.
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.
Application Development Description and exemplification of server-side scripting language for server connection, database selection, execution of SQL queries.
PHP1-1 PHP & SQL Xingquan (Hill) Zhu
© Yanbu University College YANBU UNIVERSITY COLLEGE Management Science Department © Yanbu University College Module 6:WEB SERVER AND SERVER SIDE SCRPTING,
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:
CSCI 6962: Server-side Design and Programming JDBC Database Programming.
Advanced Database Management System Lab no. 11. SQL Commands (for MySQL) –Update –Replace –Delete.
Chapter 7 PHP Interacts with Ms. Access (Open DataBase Connectivity (ODBC))
Sayed Ahmed Computer Engineering, BUET, Bangladesh MSC, Computer Science, U of Manitoba, Canada
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)
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
Accessing MySQL with PHP IDIA 618 Fall 2014 Bridget M. Blodgett.
Introduction to MySQL Lab no. 10 Advance Database Management System.
PHP MySQL. SQL: Tables CREATE TABLE tablename { fieldname type(length) extra info,... } Extra info: –NULL (allows nulls in this field) –Not NULL (null.
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.
NMED 3850 A Advanced Online Design January 12, 2010 V. Mahadevan.
1. Connecting database from PHP 2. Sending query 3. Fetching data 4. Persistent connections 5. Best practices.
Oracle SQL Query and Transactions By Shyam Gurram.
Lecture 10 – MYSQL and PHP (Part 2)
(Chapter 10 continued) Our examples feature MySQL as the database engine. It's open source and free. It's fully featured. And it's platform independent.
Accessing Your MySQL Database from the Web with PHP (Ch 11) 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.
Copyright © Curt Hill Stored Procedures In Transact-SQL.
Remote programs and commands In this presentation… –rpc concepts –rpc connections –rpc actions.
Advanced SQL: Cursors & Stored Procedures
Accessing Your MySQL Database from the Web with PHP (Ch 11) 1.
Session 7: Getting PHP to Talk to MySQL. Objectives Connecting to the Database Building & Executing the SQL SELECT Query Fetching & Displaying the data.
CHAPTER 9 PHP AND MYSQL. A POSSIBLE SITE CONFIGURATION Application Folder index.php includes (folder)header.phpfooter.phpstyle.cssmodel (folder)mysqli_connect.php.
PHP PDO & PHP SOAP Introduce. Agenda What is PHP PDO and PHP SOAP? Setup PHP PDO to connect database, query database and close the connection. Setup SOAP.
PHP PHP: Hypertext Preprocesor Personal Home Page Tools.
SQL Injection Jason Dunn. SQL Overview Structured Query Language For use with Databases Purpose is to retrieve information Main Statements Select Insert.
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 getting data from a MySQL database. Replacing XML as data source with MySQL Previously we obtained the data about the training session from an XML.
NMD202 Web Scripting Week5. What we will cover today PHP & MySQL Displaying Dynamic Pages Exercises Modifying Data PHP Exercises Assignment 1.
CSCI 6962: Server-side Design and Programming JSF DataTables and Shopping Carts.
WEB SECURITY WEEK 2 Computer Security Group University of Texas at Dallas.
PHP and SQL Server: Connection IST2101. Typical web application interaction (php, jsp…) database drivers 2IST210.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Chapter 8 Manipulating MySQL Databases with PHP PHP Programming with MySQL 2 nd Edition.
CHAPTER 10 PHP MySQL Database
SQlite. SQLite is a opensource SQL database that stores data to a text file on a device. Android comes in with built in SQLite database implementation.
CSC 2720 Building Web Applications Accessing MySQL from PHP.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 6: Accessing a database with PHP Rob Gleasure robgleasure.com.
Aggregator  Performs aggregate calculations  Components of the Aggregator Transformation Aggregate expression Group by port Sorted Input option Aggregate.
Error-based SQL Injection
Module of the week Webform 7.x-4.0-alpha9 – admin/config/content/webform Add content types, choose allowed fields, default values and advanced options.
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.
Web Systems & Technologies
Server-Side Application and Data Management IT IS 3105 (FALL 2009)
Introduction to Web programming
Web Programming– UFCFB Lecture
MySQL Web Application Connecting to a MySQL database
Introduction to Web programming
Presentation transcript:

Working with PHP and Postgresql

pg_connect ( string $connection_string [, int $connect_type ] ) pg_connect() opens a connection to a PostgreSQL database specified by connection_string If a second call is made to pg_connect() with the same connection_string as an existing connection, the existing connection will be returned unless you pass PGSQL_CONNECT_FORCE_NEW as connect_type. Example #1 Using pg_connect() <?php $dbconn = pg_connect("dbname=mary"); //connect to a database named "mary" $dbconn2 = pg_connect("host=localhost port=5432 dbname=mary"); // connect to a database named "mary" on "localhost" at port "5432" $dbconn3 = pg_connect("host=sheep port=5432 dbname=mary user=lamb password=foo"); //connect to a database named "mary" on the host "sheep" with a username and password $conn_string = "host=sheep port=5432 dbname=test user=lamb password=bar"; $dbconn4 = pg_connect($conn_string); //connect to a database named "test" on the host "sheep" with a username and password ?> pg_pconnect() - Open a persistent PostgreSQL connectionpg_pconnect() pg_close() - Closes a PostgreSQL connectionpg_close() pg_host() - Returns the host name associated with the connectionpg_host() pg_port() - Return the port number associated with the connectionpg_port() pg_tty() - Return the TTY name associated with the connectionpg_tty() pg_options() - Get the options associated with the connectionpg_options() pg_dbname() - Get the database namepg_dbname()

pg_query ([ resource $connection ], string $query ) pg_query() executes the query on the specified database connection. Return Values A query result resource on success or FALSE on failure. Example #1 pg_query() example \n"; }?> Example #2 Using pg_query() with multiple statements pg_fetch_array() - Fetch a row as an arraypg_fetch_array() pg_fetch_object() - Fetch a row as an objectpg_fetch_object() pg_num_rows() - Returns the number of rows in a resultpg_num_rows() pg_affected_rows() - Returns number of affected records (tuplespg_affected_rows()

array pg_fetch_row ( resource $result [, int $row ] ) pg_fetch_row() fetches one row of data from the result associated with the specified result resource. Parameters result PostgreSQL query result resource, returned by pg_query(), pg_query_params() or pg_execute() (among others).pg_query()pg_query_params() pg_execute() row Row number in result to fetch. Rows are numbered from 0 upwards. If omitted, next row is fetched. Example #1 pg_fetch_row() example \n"; } ?> pg_query() - Execute a querypg_query() pg_fetch_array() - Fetch a row as an arraypg_fetch_array() pg_fetch_object() - Fetch a row as an objectpg_fetch_object() pg_fetch_result() - Returns values from a result resourcepg_fetch_result()

array pg_fetch_array ( resource $result [, int $row [, int $result_type ]] ) pg_fetch_array() returns an array that corresponds to the fetched row (record). Parameters result PostgreSQL query result resource, returned by pg_query(), pg_query_params() or pg_execute() (among others).pg_query()pg_query_params()pg_execute() row Row number in result to fetch. Rows are numbered from 0 upwards. If omitted, next row is fetched. Return ValuesAn array indexed numerically (beginning with 0) or associatively (indexed by field name), or both. Each value in the array is represented as a string.array string Example #1 pg_fetch_array() example

array pg_fetch_all ( resource $result ) pg_fetch_all() returns an array that contains all rows (records) in result resource. PostgreSQL query result resource, returned by pg_query(), pg_query_params() or pg_execute() (among others).pg_query()pg_query_params()pg_execute() Example #1 PostgreSQL fetch all The above example will output something similar to: Array ( [0] => Array ( [id] => 1 [name] => Fred ) [1] => Array ( [id] => 2 [name] => Bob ) ) pg_fetch_row() - Get a row as an enumerated arraypg_fetch_row() pg_fetch_array() - Fetch a row as an arraypg_fetch_array() pg_fetch_object() - Fetch a row as an objectpg_fetch_object() pg_fetch_result() - Returns values from a result resourcepg_fetch_result()

string pg_last_error ([ resource $connection ] ) pg_last_error() returns the last error message for a given connection. Parameters connection PostgreSQL database connection resource. When connection is not present, the default connection is used. The default connection is the last connection made by pg_connect() or pg_pconnect().pg_connect() pg_pconnect() Return Values A string containing the last error message on the given connection, or FALSE on error.string Example #1 pg_last_error() example pg_result_error() - Get error message associated with resultpg_result_error() pg_result_error_field() - Returns an individual field of an error report.pg_result_error_field()

pg_execute ([ resource $connection ], string $stmtname, array $params ) Sends a request to execute a prepared statement with given parameters, and waits for the result. pg_execute() is like pg_query_params(), but the command to be executed is specified by naming a previously-prepared statement, instead of giving a query string. This feature allows commands that will be used repeatedly to be parsed and planned just once, rather than each time they are executed. The statement must have been prepared previously in the current session.pg_query_params() Example #1 Using pg_execute() <?php // Connect to a database named "mary“ $dbconn = pg_connect("dbname=mary"); // Prepare a query for execution $result = pg_prepare($dbconn, "my_query", 'SELECT * FROM shops WHERE name = $1'); // Execute the prepared query. Note that it is not necessary to escape // the string "Joe's Widgets" in any way $result = pg_execute($dbconn, "my_query", array("Joe's Widgets")); // Execute the same prepared query, this time with a different parameter $result = pg_execute($dbconn, "my_query", array("Clothes Clothes Clothes")); ?> pg_prepare() - Submits a request to create a prepared statement with the given parameters, and waits for completion.pg_prepare() pg_send_prepare() - Sends a request to create a prepared statement with the given parameters, without waiting for completion.pg_send_prepare() pg_query_params() - Submits a command to the server and waits for the result, with the ability to pass parameters separately from the SQL command text.pg_query_params()