ActiveRecord ruby:php + Ruby with ActiveRecord case
Source: Internet
Author: User
If your boss wants to use PHP, but you're a ruby fanatic, this. What do we do?
It's okay! Write in Ruby, PHP just do a little bit of processing!
How to? PHP has this function: exec
(This example is for Windows XP Professional with instantrails; not tested on other operating systems, but you can still try it)
Let's try to see!
First write a test.rb:
#!/usr/bin/env Ruby
#
# FILENAME:TEST.RB
#
Puts "Hello"
Puts "world"
Write another test.php:
<?php
EXEC ("test.rb", $args);
foreach ($arg as $args)
Echo $arg. "<br/>";
?>
After the two files are in the same catalogue, open the browser to browse the test.php; look! Did the results come out?
OK, let's go ahead and use ActiveRecord to help us add information!
We need a regular page, a PHP web and a ruby file:
#!/usr/bin/env Ruby
#
# FILENAME:AR.RB
#
Require ' RubyGems '
Gem ' ActiveRecord '
Activerecord::base.establish_connection (
: Adapter => ' MySQL ',
: Host => ' localhost ',
: username => ' Root ',
:p assword => ',
:d atabase => ' Cal '
)
Class Event < Activerecord::base;end
Name, DESCR = Argv[0], argv[1]
Puts Event.new ({: Name => name,:d escr => descr,:d ate => date.today,: Time => Time.now}). Save
OK, next is the normal page, this is the Send out form:
This is the PHP Web:
<?php
filename:ar_save.php
EXEC ("2.rb". $_post["Usrname"]. " " . $_post["Descr"], $arg);
if ($arg [0]) echo "success!";
?>
OK, let's try to see! This article links http://www.cxybl.com/html/wlbc/Php/20120607/28694.html
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service