我们首先实现一个最简单的情况,就是只查一条记录,就是select xm from mzpatient where patientid='0000002'这种形式。
在服务器端编写一个cgi程序yb_cgi_reader.cgi,内容是:
点击(此处)折叠或打开
- #!"D:\Strawberry\perl\bin\perl
- use CGI;
- use DBI;
- $dbh = DBI->connect("DBI:SQLite:dbname=his.db");
- $co = new CGI;
- print $co->header,
- $co->start_html(
- -title=>'CGI Example',
- -author=>'yourName',
- -BGCOLOR=>'white',
- -LINK=>'red'
- );
- if ($co->param()) {
- $sql = $co->param('sql');
- $sql5 = qq($sql) ;
- $sth5 = $dbh->prepare( $sql5 ) or print "Couldn't prepare statement: " . $dbh5->errstr;
- $sth5->execute() or print "Couldn't execute statement:
点击(此处)折叠或打开
- use HTTP::Request::Common;
- use LWP::UserAgent;
- sub sendsql()
- {
- $sql = shift;
- $user_agent = LWP::UserAgent->new;
- $request = POST 'http://192.168.0.6/perl/his2/yb_cgi_reader.cgi',
- [sql => "$sql", text => ''];
- $response = $user_agent->request($request);
- return $response->as_string;
- }
- 1
点击(此处)折叠或打开
- require "sub_yb_cgisender.pl";
- $sql = qq(select rybm from zd_people where peoplename = '$operer');
- $result = &sendsql($sql);
- if ($result=~/<em>(.*?)<\/em>/)
- { $sfryxm = $1; }
再写个复杂一些的,一个sql语句包含多项字段。服务端yb_cgi_reader2.cgi内容为
点击(此处)折叠或打开
- #!"D:\Strawberry\perl\bin\perl
- # 处理由其他电脑命令行传来的sql语句
- use CGI;
- use DBI;
- $dbh = DBI->connect("DBI:SQLite:dbname=his.db");
- $co = new CGI;
- print $co->header,
- $co->start_html(
- -title=>'CGI Example',
- -author=>'yourName',
- -BGCOLOR=>'white',
- -LINK=>'red'
- );
- if ($co->param()) {
- $sql = $co->param('sql');
- $sql5 = qq($sql) ;
- $sth5 = $dbh->prepare( $sql5 ) or print "Couldn't prepare statement: " . $dbh5->errstr;
- $sth5->execute() or print "Couldn't execute statement:
点击(此处)折叠或打开
- use HTTP::Request::Common;
- use LWP::UserAgent;
- sub sendsql2()
- {
- $sql = shift;
- $user_agent = LWP::UserAgent->new;
- $request = POST 'http://192.168.0.6/perl/his2/yb_cgi_reader2.cgi',
- [sql => "$sql", text => ''];
- $response = $user_agent->request($request);
- return $response->as_string;
- }
- 1
调用实例:
点击(此处)折叠或打开
- require "sub_yb_cgisender2.pl";
- # 识别刚录入的医保类型的处方编号
- $sql = qq(select reg_note.regnoteid,mzpatient.patientid,mzpatient.sexid,mzpatient.patientname,reg_note.notetype from mzpatient,reg_note where mzpatient.patientid=reg_note.patientid and mzpatient.leixing='yibao' and reg_note.tobilled='0' and reg_note.operer !='D' and reg_note.jshid is null order by reg_note.makenotetime desc limit 0,8);
- $result = &sendsql2($sql);
- @line = ($result=~/<em>(.*?)<\/em>/isg);
- foreach $l (@line)
- {
- @temp = split (" ",$l);
- $regnoteid[$i] = $temp[0];
- $patientid[$i] = $temp[1];
- $sexid[$i] = $temp[2];
- $patientname[$i] = $temp[3];
- $notetype[$i++] = $temp[4];
- }