Home Database Mysql Tutorial Mysql入门系列:Perl 脚本的特点_MySQL

Mysql入门系列:Perl 脚本的特点_MySQL

Jun 01, 2016 pm 01:56 PM
how interface database

  本章介绍如何使用Perl DBI 与MySQL接口。我们不讨论DBI 的基本原理或体系结构。有关DBI 这些方面的信息(特别是与C 和PHP API 的比较),请参阅第5 章。

  本章的举例动用了样例数据库samp_db,使用了学分保存方案和历史同盟需要的表。想要从本章中取得最大收获,最好了解一些有关Perl 的知识。如果不想这样,那么通过拷贝这里看到的样例代码,也能有所帮助,并可以编写自己的脚本,不过找一本好的Perl 书,可能仍是一件非常有价值的投资。有这样一本书,名为《Programming Perl 》,第二版是由Wa l l、C h r i s t i a n s e n、Schwartz 和P o t ter(O’ Reilly出版社19 9 6出版)撰写的。(机械工业出版社1999年已出版了《Perl 5编程详解》―编者注。)

  DBI 的当前版本为1. 13,但是此处的大部分介绍也可用于更早的1.xx 版本。请注意,对所介绍的早期版本中没有出现的特性作了说明。

  MySQL的DBI 需要至少为5.004_05 的Perl 版本。另外还必须安装Msql-Mysql 模块和Data-Dumper Perl 模块,以及MySQLC 客户机库和一些头文件。如果计划编写基于Web 的DBI 脚本,则要使用CGI.pm 模块。本章中,这个模块用于与Apache Web 服务器的连接。如

  果需要获得这样的程序包,请参阅附录A。该附录中也给出了获得本章开发的样例脚本的说明。可以下载这些脚本,不必自己键入。

  很大程度上,本章介绍Perl DBI 的方法和变量只是出于讨论的需要。至于所有方法和变量的更全面的列表,请参阅附录G。如果要使用DBI 的任何部分,可以用该附录作为进一步研究的背景材料。可通过运行下面的命令来得到联机文档:

  % perldoc DBI

  % perldoc DBI::FAQ

  % perldoc DBI::mysql  在数据库驱动程序( DB D)级,MySQL的驱动程序建立在MySQLC 客户机库的基础之上,因而具有它的某些特性。有关该库的详细信息,请参阅第6 章。

  Perl 脚本为文本文件,可以利用任何文本编辑器来创建它们。本章所有的Perl 脚本都遵从UNIX 的约定,第一行以‘ #!’开始,接着是执行这个脚本要使用的程序路径名。第一行如下所示:

  #! /usr/bin/perl

  如果在您的系统中,路径名不是Perl,如为/usr/local/bin/perl5 或/ o p t / b i n / per l,则需要修改‘# !’行。否则,Perl 脚本不能在系统中正确运行。

  在‘#!’之后含有一个空格,这是因为有的系统会将‘ #! /’解释为4 个字节的怪异数字,所以如果没有空格,则忽略这一行,这样,会将相应脚本作为外壳脚本来对待。

  在UNIX 系统中,应该使Perl 脚本成为可执行文件,以便只要键入其名称就可执行。为使脚本成为可执行文件,对文件模式做如下更改即可:

  % chmod +X script_name

  如果在Windows 下使用ActiveState Perl,则不必使脚本成为可执行文件,可如下运行一个脚本:

  C:> perl script_name

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)

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

How to handle database connection errors in PHP How to handle database connection errors in PHP Jun 05, 2024 pm 02:16 PM

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

Application of interfaces and abstract classes in design patterns in Java Application of interfaces and abstract classes in design patterns in Java May 01, 2024 pm 06:33 PM

Interfaces and abstract classes are used in design patterns for decoupling and extensibility. Interfaces define method signatures, abstract classes provide partial implementation, and subclasses must implement unimplemented methods. In the strategy pattern, the interface is used to define the algorithm, and the abstract class or concrete class provides the implementation, allowing dynamic switching of algorithms. In the observer pattern, interfaces are used to define observer behavior, and abstract or concrete classes are used to subscribe and publish notifications. In the adapter pattern, interfaces are used to adapt existing classes. Abstract classes or concrete classes can implement compatible interfaces, allowing interaction with original code.

How to use database callback functions in Golang? How to use database callback functions in Golang? Jun 03, 2024 pm 02:20 PM

Using the database callback function in Golang can achieve: executing custom code after the specified database operation is completed. Add custom behavior through separate functions without writing additional code. Callback functions are available for insert, update, delete, and query operations. You must use the sql.Exec, sql.QueryRow, or sql.Query function to use the callback function.

How to connect to remote database using Golang? How to connect to remote database using Golang? Jun 01, 2024 pm 08:31 PM

Through the Go standard library database/sql package, you can connect to remote databases such as MySQL, PostgreSQL or SQLite: create a connection string containing database connection information. Use the sql.Open() function to open a database connection. Perform database operations such as SQL queries and insert operations. Use defer to close the database connection to release resources.

Inner class implementation of interfaces and abstract classes in Java Inner class implementation of interfaces and abstract classes in Java Apr 30, 2024 pm 02:03 PM

Java allows inner classes to be defined within interfaces and abstract classes, providing flexibility for code reuse and modularization. Inner classes in interfaces can implement specific functions, while inner classes in abstract classes can define general functions, and subclasses provide concrete implementations.

How to handle database connections and operations using C++? How to handle database connections and operations using C++? Jun 01, 2024 pm 07:24 PM

Use the DataAccessObjects (DAO) library in C++ to connect and operate the database, including establishing database connections, executing SQL queries, inserting new records and updating existing records. The specific steps are: 1. Include necessary library statements; 2. Open the database file; 3. Create a Recordset object to execute SQL queries or manipulate data; 4. Traverse the results or update records according to specific needs.

See all articles