html5中文学习网

您的位置: 首页 > 网络编程 > PHP编程 » 正文

activerecord ruby:php + ruby with activerecord 例_PHP教程_编程技术

[ ] 已经帮助:人解决问题

如果老要求使用php,可是您是ruby狂者,.. 怎呢?
! 一用ruby,php只要做一的理就好!
how to? php中有函式:exec
( 本例作於windows xp professional搭配instantrails;在其他作系上有,不各位是可以看看 )
我看吧!
先test.rb:
#!/usr/bin/env ruby
#
# filename: test.rb
#
puts "hello"
puts "world"

再test.php:
<?php
exec("test.rb", $args);
foreach($arg as $args)
echo $arg . "<br />";
?>
案放在同一目下後,打器test.php;看!是不是示果出了?
ok,我直接用activerecord我新增料吧!
我需要一普通面、一php跟一ruby案:
#!/usr/bin/env ruby
#
# filename: ar.rb
#
require 'rubygems'
gem 'activerecord'
activerecord::base.establish_connection(
:adapter => 'mysql',
:host => 'localhost',
:username => 'root',
:password => '',
:database => 'cal'
)

class event < activerecord::base;end

name, descr = argv[0], argv[1]
puts event.new({:name => name, :descr => descr, :date => date.today, :time => time.now}).save
好了,接下是普通面,是送出表:

<!-- filename: ar_form.html -->
<html>
<head>
<title>php with ruby and activerecord</title>
</head>
<body>
<form action="ar_save.php" method="post">
username: <input type="text" name="usrname" /><br />
description: <textarea name="descr"></textarea><br />
<input type="submit" value="save it!" />
</form>
</body>
</html>

是php:
<?php
// filename: ar_save.php
exec("2.rb " . $_post["usrname"] . " " . $_post["descr"], $arg);
if($arg[0]) echo "success!";
?>
ok,我看吧! 本文链接http://www.cxybl.com/html/wlbc/Php/20120607/28694.html
AWnHTML5中文学习网 - HTML5先行者学习网
AWnHTML5中文学习网 - HTML5先行者学习网
(责任编辑:)
推荐书籍
推荐资讯
关于HTML5先行者 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助