Home Backend Development PHP Tutorial 通过dbi使用perl连接mysql数据库的方法_PHP

通过dbi使用perl连接mysql数据库的方法_PHP

Jun 01, 2016 am 11:54 AM
perl

通过使用DBI,用Perl可以很容易的连接到mysql数据库:

代码如下:
复制代码 代码如下:
#!/bin/perl

use DBI;

# Connect to target DB
my $dbh = DBI->connect("DBI:mysql:database=eygle;host=localhost","username","password", {'RaiseError' => 1});

# Insert one row
my $rows = $dbh->do("INSERT INTO test (id, name) VALUES (1, 'eygle')");

# query
my $sqr = $dbh->prepare("SELECT name FROM test");
$sqr->execute();

while(my $ref = $sqr->fetchrow_hashref()) {
print "$ref->{'name'}n";
}

$dbh->disconnect();

执行结果:

复制代码 代码如下:
[root@eygle ~]# perl test.cgi
eygle

以后很多统计数据可以直接通过Perl写入Mysql数据库,操作起来方便多了。

Statement of this Website
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

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Develop efficient web crawlers and data scraping tools using Vue.js and Perl languages Develop efficient web crawlers and data scraping tools using Vue.js and Perl languages Jul 31, 2023 pm 06:43 PM

Use Vue.js and Perl languages ​​to develop efficient web crawlers and data scraping tools. In recent years, with the rapid development of the Internet and the increasing importance of data, the demand for web crawlers and data scraping tools has also increased. In this context, it is a good choice to combine Vue.js and Perl language to develop efficient web crawlers and data scraping tools. This article will introduce how to develop such a tool using Vue.js and Perl language, and attach corresponding code examples. 1. Introduction to Vue.js and Perl language

Best practices for building high-performance web applications using Python and Perl Best practices for building high-performance web applications using Python and Perl Jun 17, 2023 am 08:09 AM

In today's digital age, web applications are becoming more and more common, making our lives more convenient and efficient. Python and Perl are two widely used programming languages, both of which are ideal for building web applications. However, to build high-performance web applications, you need to master some best practices. This article will introduce some best practices for building high-performance web applications in Python and Perl. Choosing the right web framework Choosing a suitable web framework is a critical step in designing high-performance web applications.

Develop system scripts and automation tools using Vue.js and Perl languages Develop system scripts and automation tools using Vue.js and Perl languages Jul 29, 2023 pm 04:57 PM

Using Vue.js and Perl language to develop system scripts and automation tools In the current software development environment, system scripts and automation tools have become important tools for developers to save time and improve efficiency. In this article, we will introduce how to develop system scripts and automation tools using Vue.js and Perl language, and provide some code examples. Vue.js is a popular JavaScript framework for building user interfaces. It adopts a component-based development approach, allowing developers to

How to use Nginx as a Perl program server and its Perl module under Linux How to use Nginx as a Perl program server and its Perl module under Linux May 16, 2023 pm 11:25 PM

Building perl+fastcgi+nginx nginx+fastcgi is the most popular environment under PHP. Will perl also have fastcgi? Of course it does. Today, let’s build perl’s fastcgi under nginx. The performance is no less than that of PHP. But now the popularity of the web program PHP is unmatched by perl. No matter how good the performance is, it is in vain. However, some small functions can be solved by using perl's fastcgi. Let's get to the point. 1. Prepare the software environment: nginxperl: The system comes with fastcgi1.2perl installation Generally, Linux comes with perl, so you don’t need to install it. If it doesn’t, please execute:

Redis and Perl language development: building efficient command line tools Redis and Perl language development: building efficient command line tools Jul 31, 2023 pm 04:09 PM

Redis and Perl language development: building efficient command line tools Introduction: Redis is an open source in-memory data storage system written in C language. It has high performance and flexible features and is widely used in scenarios such as caching, message queues and real-time analysis. . Perl is a scripting language with powerful text processing and regular expression capabilities, making it ideal for rapid development of command-line tools. This article will introduce how to use Perl language and Redis to build efficient command line tools, and provide relevant code examples. one

How to develop recommendation system functionality using Redis and Perl How to develop recommendation system functionality using Redis and Perl Sep 22, 2023 am 09:24 AM

How to use Redis and Perl to develop recommendation system functions Recommendation system is a very important part of modern Internet applications, which can help users discover content or products that may be of interest to them. In this article, we will introduce how to develop a simple recommendation system function using Redis and Perl, and provide specific code examples. First, let's understand the basic concepts of Redis and Perl. Redis is an open source in-memory data storage system that can be used as a database, cache, and messaging middleware. it

The difference between Golang and Perl in system programming The difference between Golang and Perl in system programming May 31, 2024 pm 06:07 PM

The following key differences exist between Golang and Perl in systems programming: Concurrency: Golang is a concurrent language, while Perl uses external modules to implement concurrency. Memory management: Golang uses garbage collection, Perl uses manual memory management. Compilation and interpretation: Golang is a compiled language, and Perl is an interpreted language. Practical case: Golang is simple and efficient in the example of checking whether a file exists and returning its size.

How to develop a simple key-value storage function using Redis and Perl How to develop a simple key-value storage function using Redis and Perl Sep 22, 2023 am 09:00 AM

How to use Redis and Perl to develop a simple key-value storage function Introduction: Redis is an open source in-memory data structure storage system that can be used to store and access data efficiently. Perl is an advanced scripting programming language with rich text processing capabilities and convenient module integration. This article will introduce how to use Redis and Perl to develop simple key-value storage functions, and provide specific code examples. 1. Install Redis and Perl modules. First, you need to install Red on the server.

See all articles