search
HomeBackend DevelopmentPHP TutorialTwo PostgreSQL data connection methods and operation examples_PHP tutorial

Two PostgreSQL data connection methods and operation examples

Two postgreSQL data connection methods and operation examples.

$pg=@pg_connect("host=localhost user=postgres password=sa dbname=employes")
or die("can't connect to database.");
$query="select * from employees order by serial_no";

//$query="insert into employees values(10008,'susan','1985-09-04','80','50')";
$result=@pg_query($pg,$query) or die("can't run query to table.");
//echo pg_num_rows($result); //How many records are output to be queried
//if($result)
//{
//echo "recrods inserted successfully!";
//echo pg_affected_rows($result);//Output how many records have been inserted
//}

//Example 1 [pg_fetch_row]
echo "

";
echo "";
echo "";
echo"";
echo"";
echo"";

for($i=0;$i {

$row=@pg_fetch_row($result) or die("can't fetch row from table.");
$serial_no= $row[0];
$name= $row[1];
$birthday= $row[2];
echo"

";
echo"";
echo"";
echo"";
echo"";

}
echo"

serial_nonamebirthday
$serial_no$name$birthday
";

//Example 2 [pg_fetch_array]
//echo "

";
//echo "";
//echo "";
//echo"";
//echo"";
//echo"";
//
//for($i=0;$i //{
//
//$row=@pg_fetch_array($result) or die("can't fetch row from table.");
//$serial_no= $row['serial_no'];
//$name= $row['name'];
//$birthday= $row['birthday'];
//echo"";
//echo"";
//echo"";
//echo"";
//echo"";
//
//}
//echo"
serial_nonamebirthday
$serial_no$name$birthday
";

//Add, delete, modify instances
//$newrow=array("serial_no"=>"1006","name"=>"peter","birthday"=>"1990-07-03","salary"=>"90" ,"bonus"=>"80");
//$reusult=@pg_insert($pg,"employes",$newrow) or die("can't insert data to table.");
//if($reusult)
//{
//echo "rechords inserted successfully!";
//}
//
pg_close($pg);

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/630835.htmlTechArticleTwo PostgreSQL methods and operation examples for connecting data. Two postgresql methods and operation examples for connecting data. $pg= @pg_connect(host=localhost user=postgres password=sa dbname=employes)...
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
使用PHP连接MariaDB数据库使用PHP连接MariaDB数据库May 17, 2023 am 08:24 AM

MariaDB是一种开源的关系型数据库管理系统,它是MySQL的一个分支。PHP作为一种开源的服务器端脚本语言,被广泛应用于Web开发中。在很多Web开发项目中,需要使用PHP连接到MariaDB数据库,以便在Web应用程序中存储和检索数据。这篇文章将介绍如何使用PHP编写代码来连接MariaDB数据库。一、安装MariaDB服务器在使用PHP连接Maria

PHP8.0中的连接多个任务库PHP8.0中的连接多个任务库May 14, 2023 am 09:01 AM

随着现代程序开发的不断发展,软件项目往往需要同时使用多个任务库来处理不同的任务。PHP语言一直是Web开发的重要工具,其在7.0版本中引入了新的并发处理特性,使得PHP在处理任务库时更加高效、灵活。在8.0版本中,PHP又新增了对连接多个任务库的支持,这为我们在处理大量数据和并发请求时提供了极大的便利。在本文中,我们将探讨PHP8.0中连接多个任务库的方法和

MySQL和PostgreSQL:在Web开发中的最佳实践MySQL和PostgreSQL:在Web开发中的最佳实践Jul 14, 2023 pm 02:34 PM

MySQL和PostgreSQL:在Web开发中的最佳实践引言:在现代的Web开发领域中,数据库是必不可少的组成部分。在选择数据库时,常见的选择是MySQL和PostgreSQL。本文将介绍在Web开发中使用MySQL和PostgreSQL的最佳实践,并提供一些代码示例。一、适用场景MySQL适用于大多数Web应用程序,特别是那些需要高性能、可扩展性和易于使

MySQL和PostgreSQL:性能对比与优化技巧MySQL和PostgreSQL:性能对比与优化技巧Jul 13, 2023 pm 03:33 PM

MySQL和PostgreSQL:性能对比与优化技巧在开发web应用程序时,数据库是不可或缺的组成部分。而在选择数据库管理系统时,MySQL和PostgreSQL是两个常见的选择。他们都是开源的关系型数据库管理系统(RDBMS),但在性能和优化方面有一些不同之处。本文将比较MySQL和PostgreSQL的性能,并提供一些优化技巧。性能对比在比较两个数据库管

MySQL和PostgreSQL:数据安全与备份策略MySQL和PostgreSQL:数据安全与备份策略Jul 13, 2023 pm 03:31 PM

MySQL和PostgreSQL:数据安全与备份策略引言:在现代社会中,数据成为了企业和个人生活中不可或缺的一部分。对于数据库管理系统来说,数据安全与备份策略是至关重要的,既能保护数据免受丢失或损坏,也能确保恢复数据的可靠性和完整性。本文将重点讨论MySQL和PostgreSQL两种主流关系型数据库系统的数据安全性和备份策略。一、数据安全性方面:(一)用户权

在Go语言中使用PostgreSQL:完整指南在Go语言中使用PostgreSQL:完整指南Jun 18, 2023 am 09:28 AM

Go语言是一种快速、高效的编程语言,适合构建Web服务和后端应用程序。而PostgreSQL是一个开源的关系型数据库管理系统,承诺提供更高的可靠性、可扩展性和数据安全性。在本文中,我们将深入探讨如何在Go语言中使用PostgreSQL,并提供一些实用的代码示例和技巧。安装和设置PostgreSQL首先,我们需要安装和设置PostgreSQL。可以在官方网

学习Go语言中的数据库函数并实现PostgreSQL数据的增删改查操作学习Go语言中的数据库函数并实现PostgreSQL数据的增删改查操作Jul 31, 2023 pm 12:54 PM

学习Go语言中的数据库函数并实现PostgreSQL数据的增删改查操作在现代的软件开发中,数据库是不可或缺的一部分。Go语言作为一门强大的编程语言,提供了丰富的数据库操作函数和工具包,可以轻松地实现数据库的增删改查操作。本文将介绍如何学习Go语言中的数据库函数,并使用PostgreSQL数据库进行实际的操作。第一步:安装数据库驱动程序在Go语言中,每个数据库

如何在PHP编程中使用PostgreSQL数据库?如何在PHP编程中使用PostgreSQL数据库?Jun 12, 2023 am 09:27 AM

随着数据库技术的发展,数据库管理系统也呈现出多种多样的选择,开发人员可以根据自己的需求和喜好选择最适合自己的数据库。而PostgreSQL作为一种先进的开源关系型数据库系统,越来越受到开发人员的关注和使用。那么,在PHP编程中如何使用PostgreSQL数据库呢?一、安装和配置PostgreSQL数据库在使用PostgreSQL之前,需要先安装和配置它。首先

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment