簡體   English   中英

Perl無法連接數據庫

[英]perl not able to connect database

我是Perl編程的新手。 我嘗試了基本的perl數據庫連接,並得到以下錯誤。 請任何人幫助如何解決此問題。

"use" not allowed in expression at ./database.pl line 4, at end of line
syntax error at ./database.pl line 4, near "use DBI
use strict"
Execution of ./database.pl aborted due to compilation errors.

database.pl文件

#!/usr/bin/perl

use DBI
use strict;

my $driver = "mysql";
my $database = "pj_order";
my $dsn = "DBI:$driver:database=$database;host=localhost";
my $userid = "root";
my $password = "root";

my $dbh = DBI->connect($dsn, $userid, $password ) or die $DBI::errstr;

最后,我已經運行了database.pl文件,並得到以下錯誤。

"use" not allowed in expression at ./database.pl line 4, at end of line
syntax error at ./database.pl line 4, near "use DBI
use strict"
Execution of ./database.pl aborted due to compilation errors.
use DBI

應該

use DBI;

最好放在之后

use strict;

你還應該有

use warnings qw( all );

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM