搜尋
首頁php教程php手册PHP ORM使用之

NORM 是一款PHP ORM 框架 何为ORM 可以去搜下。。 下面是使用NOrm创建两个表 ?php include_once libs/norm.php ; /*首先定义数据对象模型 一个类相当于一个表*/ $norm = new Norm(mysql:dbname=test;host=127.0.0.1,root,xxxx); class Costume{ } $costume =

  NORM 是一款PHP ORM 框架 何为ORM 可以去搜下。。

 

 下面是使用NOrm创建两个表

   include_once "libs/norm.php"  ;
   /*首先定义数据对象模型 一个类相当于一个表*/
$norm = new Norm("mysql:dbname=test;host=127.0.0.1","root","xxxx");

class Costume{ }
$costume = new Costume();
$costume->title = 'Scary Mask';
$costume->sku   = '324-2444-234';
$costume->price = '19.95';
$norm->store($costume);
echo "Costume Id: {$costume->id}
";   / /输出的是此次添加产生的ID  在我们的对象模型不要有id属性 norm自动添加 否则出错

class News{ }
$news=new News() ;
$news->content="dsds";
$news->date="2010-01-02" ;
$norm->store($news) ;

 

//获取表中所有记录

class Costume{ }
  $constume=new Costume() ;
  $res=$norm->get($constume)->results ;
  print_pre($res);

 

//获取表中id为1 的记录

 class Costume{ }
  $constume=new Costume() ;
  $constume->id="1";
  $res=$norm->get($constume)->results ;
  print_pre($res);

 

//修改表中ID是1的行数据

 class Costume{ }
  $constume=new Costume() ;
  $constume->id="1";
  $constume->title="dsds";
  $norm->store($constume);

 

/*返回date是如下的数据行的 id 和date Norm::SINGLE 不返回完整的列的时候要指定  */

class News {}
$news   = new News();
$news->date = "2010-01-02";
print "

".print_pre($norm->get($news,'news_id,news_date',Norm::SINGLE)->results,true)."
";
?>

 

 

setTablePrefix   //设置表前

stuff  打乱提交的数据数据一 user[usname]  user[password]方式提交最好 

get 返回的是表的数组  get['table'][0]

 

//删除制定表的制定行 通过ID

class News {}
$news   = new News();
$news->id = "1";
$norm->del($news) ;

 

 

 

?>

 

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

強大的PHP整合開發環境

VSCode Windows 64位元 下載

VSCode Windows 64位元 下載

微軟推出的免費、功能強大的一款IDE編輯器

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

將Eclipse與SAP NetWeaver應用伺服器整合。

PhpStorm Mac 版本

PhpStorm Mac 版本

最新(2018.2.1 )專業的PHP整合開發工具