pdoone。它是与SQL Server(2008 R2或更高),MySQL(5.7或更高)和Oracle(12.1或更高)兼容的PHP PDO库的简单包装器。
该图书馆试图尽可能快地工作。大多数操作都是简单的字符串/数组管理,并在PDO库的裸机中工作,但它还允许使用扩展EFTEC/PDOONEORM创建ORM。
转
$ stmt = $ pdo -> prepare ( " SELECT * FROM myTable WHERE name = ? " );
$ stmt -> bindParam ( 1 , $ _POST [ ' name ' ], PDO :: PARAM_STR );
$ stmt -> execute ();
$ result = $ stmt -> get_result ();
$ products =[];
while ( $ row = $ result -> fetch_assoc ()) {
$ product []= $ row ;
}
$ stmt -> close ();进入这个
$ products = $ pdoOne
-> select ( " * " )
-> from ( " myTable " )
-> where ( " name = ? " ,[ $ _POST [ ' name ' ]])
-> toList ();或使用ORM(使用EFTEC/PDOONEORM库)
ProductRepo // this class was generated with echo $pdoOne()->generateCodeClass(['Product']); or using the cli.
:: where ( " name = ? " ,[ $ _POST [ ' name ' ]])
:: toList ();| exeppleticketPHP | 纸杯蛋糕 | 示例搜索 | 示例不同的方法 |
|---|---|---|---|
![]() | ![]() | ![]() |
更多示例:
示例使用PDOONE的MySQL php和PDO
该库需要php 7.1及更高版本,并且需要扩展PDO和扩展PDO-MYSQL(MySQL),PDO-SQLSRV(SQL Server)或PDO-OCI(Oracle)
编辑Composer.json下一个要求,然后更新作曲家。
{
"require" : {
"eftec/PdoOne" : " ^4.0.1 "
}
}或使用CLI使用
作曲家需要EFTEC/PDOONE
只需从库中下载文件夹lib,然后放入您的文件夹项目即可。然后,您必须包括其中包含的所有文件。
如下创建类PDOONE的实例。然后,您可以使用方法Connect()或Open()打开连接()
use eftec PdoOne ;
// mysql
$ dao = new PdoOne ( " mysql " , " 127.0.0.1 " , " root " , " abc.123 " , " sakila " , "" );
$ conn -> logLevel = 3 ; // it is for debug purpose and it works to find problems.
$ dao -> connect ();
// sql server 10.0.0.1instance or (local)instance or machinenameinstance or machine (default instance)
$ dao = new PdoOne ( " sqlsrv " , " (local)sqlexpress " , " sa " , " abc.123 " , " sakila " , "" );
$ conn -> logLevel = 3 ; // it is for debug purpose and it works to find problems.
$ dao -> connect ();
// test (mockup)
$ dao = new PdoOne ( " test " , " anyy " , " any " , " any " , " any " , "" );
$ dao -> connect ();
// oci (oracle) ez-connect. Remember that you must have installed Oracle Instant client and added to the path.
$ cs = ' (DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = instancia1))) ' ;
$ dao = new PdoOne ( " oci " , $ cs , " sa " , " abc.123 " ); // oracle uses the user as the schema
$ conn -> logLevel = 3 ; // it is for debug purpose and it works to find problems.
$ dao -> connect ();
// oci (oracle) tsnnames (the environment variables TNS_ADMIN and PATH must be correctly configured), also tnsnames.ora must exists.
$ cs = ' instancia1 ' ;
$ dao = new PdoOne ( " oci " , $ cs , " sa " , " abc.123 " ); // oracle uses the user as the schema
$ conn -> logLevel = 3 ; // it is for debug purpose and it works to find problems.
$ dao -> connect ();在哪里
$ dao = new Pdoone(“ mysql”,“ 127.0.0.1”,“ root”,“ abc.123”,“ sakila”,“”);
Oracle安装很棘手。在Windows中,从Oracle Home的bin文件夹中,您必须将所有DLL复制到PHP文件夹和Apache文件夹。
使用方法Runrawquery() ,我们可以在有或没有参数的情况下直接执行命令到PDO。它可以返回pdostatement或数组。当我们想要速度时,这很有用。
runrawquery($ rowsql,$ param,$ returnarray,$ fetchmode,$ fetchargument)
字符串$ rawSQL执行阵列的查询| null $ param [type1,value1,type2,value2]或[name1 => value,name2 = value2] bool $ returnaray如果为true(默认),则返回一个数组。如果false,则返回pdostatement int $ fetchmode表示获取模式。示例:pdo :: fetch_assoc null $ fetchargument fetchmode的参数。
$ sql = ' select * from table where id=1 ' ;
$ pdoStatement = $ pdoOne -> runRawQuery ( $ sql ,[], false ); // [] are the parameters但是我们可以将其更改为返回一个数组
$ sql = ' select * from table where id=1 ' ;
$ values = $ pdoOne -> runRawQuery ( $ sql ); // [] are the parameters我们也可以传递参数。
$ values = $ con -> runRawQuery ( ' select * from table where id=? ' ,[ 20 ]); // with parameter
$ values = $ con -> runRawQuery ( ' select * from table where id=:name ' ,[ ' name ' => 20 ]); // with named parameter
$ values = $ con -> runRawQuery ( ' select * from table ' ,[]); // without parameter.请注意,该库使用已准备好的语句,因此它没有SQL注入(如果使用参数)
$ name = " O'hara " ;
$ values = $ con -> runRawQuery ( " select * from table where name=:name " ,[ ' name ' => $ name ]); // it works.✅
$ values = $ con -> runRawQuery ( " select * from table where name=? " ,[ $ name ]); // it works ok.✅
$ values = $ con -> runRawQuery ( " select * from table where name=' $ name ' " ); // it will crash.使用方法runquery(),我们可以在PDO中执行准备好的语句。当我们想将参数传递给它时,这很有用。 Runquery()需要准备PDO。
除非您已经使用PDO语句,否则不建议使用此方法,并且不想适应所有代码。
$ sql = " insert into `product`(name) values(?) " ;
$ stmt = $ pdoOne -> prepare ( $ sql );
$ productName = " Cocacola " ;
$ stmt -> bind_param ( " s " , $ productName ); // s stand for a string. Also i =integer, d = double and b=blob
$ rows = $ pdoOne -> runQuery ( $ stmt );
$ allRows = $ rows -> fetch_all ( PDO :: FETCH_ASSOC );您可以使用查询构建器来构建命令。您可以查看有关查询构建器(DQL)的章节,以获取更多信息。
// query builder
$ pdoOne -> set ([ ' name ' => ' cocacola ' ])
-> from ( ' product ' )
-> insert ();库eftec pdooneorm允许创建表的[orm] (#orm)。如果您生成了ORM,则可以使用下一个代码
ProductRepo:: toList ([ ' category ' => ' drink ' ]);其中productrepo是使用ORM生成的服务类。
默认情况下,PDOONE在模式pdo :: fetch_assoc中执行查询,您可以通过运行查询来更改为:
$ pdo -> setFechMode ( PDO :: FETCH_CLASS , ' stdClass ' )-> runRawQuery ( $ query );
// or you can run as
$ pdo -> runRawQuery ( $ query , null , true , false , null , PDO :: FETCH_CLASS , ' stdClass ' )PDOONE允许5种类型的日期。
SQL格式是将日期存储到数据库中的格式。这取决于数据库的类型。例如,MySQL可以使用格式YMD。
人类格式是最终用户看起来我们日期的格式。
ISO日期格式。这是如何运输和序列化值的格式。
时间戳:它计算1-1-1970之后的秒数
类 / PHP类:这是一个日期对象。
有3种运行交易的方法:
| 方法 | 描述 |
|---|---|
| startTransaction() | 它开始交易。根据类型数据库的不同,它可以堆叠。 |
| 犯罪() | 提交(并关闭)交易 |
| 回滚() | 回滚(并关闭)交易 |
例子:
try {
$ sql = " insert into `product`(name) values(?) " ;
$ pdoOne -> startTransaction ();
$ result = $ pdoOne -> runRawQuery ( $ sql ,[ ' Fanta ' => $ productName ], false );
$ pdoOne -> commit (); // transaction ok
} catch ( Exception $ e ) {
$ pdoOne -> rollback ( false ); // error, transaction cancelled, the false means that it doesn't throw an exception if we want rollback.
}如果表格存在(当前数据库/架构),则返回true
返回表的列的统计信息(作为数组)。
$ stats = $ pdoOne -> statValue ( ' actor ' , ' actor_id ' );| 最小 | 最大限度 | avg | 和 | 数数 |
|---|---|---|---|---|
| 1 | 205 | 103.0000 | 21115 | 205 |
返回表的所有列
$ result = $ pdoOne -> columnTable ( ' actor ' );| colname | Coltype | 结肠化 | Colpres | colscale | ISKEY | 现有人士 |
|---|---|---|---|---|---|---|
| actor_id | 小网 | 5 | 0 | 1 | 1 | |
| 名 | Varchar | 45 | 0 | 0 | ||
| 姓 | Varchar | 45 | 0 | 0 | ||
| last_update | 时间戳 | 0 | 0 |
返回表的所有外键(源表)
使用定义和主键创建表。
注意:您可以通过执行CLI(输出classcode)来生成代码使用现有表创建表
php pdoone.php -database mysql -Server 127.0.0.1-用户根-PWD ABC.123 -DB sakila -Input Film -Output classcode
示例:( mysql)
$ pdo -> createTable ( ' film ' ,
[
" film_id " => " smallint unsigned not null auto_increment " ,
" title " => " varchar(255) not null " ,
" description " => " text " ,
" release_year " => " year " ,
" language_id " => " tinyint unsigned not null " ,
" original_language_id " => " tinyint unsigned " ,
" rental_duration " => " tinyint unsigned not null default '3' " ,
" rental_rate " => " decimal(4,2) not null default '4.99' " ,
" length " => " smallint unsigned " ,
" replacement_cost " => " decimal(5,2) not null default '19.99' " ,
" rating " => " enum('G','PG','PG-13','R','NC-17') default 'G' " ,
" special_features " => " set('Trailers','Commentaries','Deleted Scenes','Behind the Scenes') " ,
" last_update " => " timestamp not null default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP "
],[
" film_id " => " PRIMARY KEY " ,
" title " => " KEY " ,
" language_id " => " FOREIGN KEY REFERENCES`language`(`language_id`) ON UPDATE CASCADE " ,
" original_language_id " => " FOREIGN KEY REFERENCES`language`(`language_id`) ON UPDATE CASCADE "
]); $ pdo -> createTable ( ' film ' ,
[
" film_id " => " smallint unsigned not null auto_increment " ,
" title " => " varchar(255) not null " ,
" description " => " text " ,
" release_year " => " year " ,
" language_id " => " tinyint unsigned not null " ,
" original_language_id " => " tinyint unsigned " ,
" rental_duration " => " tinyint unsigned not null default '3' " ,
" rental_rate " => " decimal(4,2) not null default '4.99' " ,
" length " => " smallint unsigned " ,
" replacement_cost " => " decimal(5,2) not null default '19.99' " ,
" rating " => " enum('G','PG','PG-13','R','NC-17') default 'G' " ,
" special_features " => " set('Trailers','Commentaries','Deleted Scenes','Behind the Scenes') " ,
" last_update " => " timestamp not null default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP "
], ' film_id ' ); 示例(SQLSRV)
$ pdo -> createTable ( ' film ' ,
[
" film_id " => " int NOT NULL IDENTITY(1,1) " ,
" title " => " varchar(255) NOT NULL " ,
" description " => " text(2147483647) DEFAULT (NULL) " ,
" release_year " => " varchar(4) " ,
" language_id " => " tinyint NOT NULL " ,
" original_language_id " => " tinyint DEFAULT (NULL) " ,
" rental_duration " => " tinyint NOT NULL DEFAULT ((3)) " ,
" rental_rate " => " decimal(4,2) NOT NULL DEFAULT ((4.99)) " ,
" length " => " smallint DEFAULT (NULL) " ,
" replacement_cost " => " decimal(5,2) NOT NULL DEFAULT ((19.99)) " ,
" rating " => " varchar(10) DEFAULT ('G') " ,
" special_features " => " varchar(255) DEFAULT (NULL) " ,
" last_update " => " datetime NOT NULL DEFAULT (getdate()) "
],[
" language_id " => " FOREIGN KEY REFERENCES language(language_id) " ,
" original_language_id " => " FOREIGN KEY REFERENCES language(language_id) " ,
" film_id " => " PRIMARY KEY "
]);它返回按依赖项订购的表的列表(从无依赖到更依赖)
注意:此操作不是万无一失的,因为桌子可能具有圆形参考。
$ dao = new PdoOne ( ' sqlsrv ' , " (local)sqlexpress " , " sa " , " abc.123 " , " sakila " );
$ dao -> open ();
echo " <pre> " ;
var_dump ( $ dao -> tableSorted ( 3 , false , true )); // it returns the tables sortered
var_dump ( $ dao -> tableSorted ( 3 , true , true )); // it returns all the tables that can't be sortered
echo " </pre> " ;如果表与值相关的定义匹配,则验证表。
$def=[
"film_id" => "int NOT NULL IDENTITY(1,1)",
"title" => "varchar(255) NOT NULL",
"description" => "text(2147483647) DEFAULT (NULL)",
"release_year" => "varchar(4)",
"language_id" => "tinyint NOT NULL",
"original_language_id" => "tinyint DEFAULT (NULL)",
"rental_duration" => "tinyint NOT NULL DEFAULT ((3))",
"rental_rate" => "decimal(4,2) NOT NULL DEFAULT ((4.99))",
"length" => "smallint DEFAULT (NULL)",
"replacement_cost" => "decimal(5,2) NOT NULL DEFAULT ((19.99))",
"rating" => "varchar(10) DEFAULT ('G')",
"special_features" => "varchar(255) DEFAULT (NULL)",
"last_update" => "datetime NOT NULL DEFAULT (getdate())"
];
$keys=[
"language_id" => "FOREIGN KEY REFERENCES language(language_id)",
"original_language_id" => "FOREIGN KEY REFERENCES language(language_id)",
"film_id" => "PRIMARY KEY"
];
var_dump(PdoOne::validateDefTable(self::getPdoOne(),self::TABLE,$def,$keys));
它返回桌子的所有外键。
$ result = $ pdoOne -> foreignKeyTable ( ' actor ' );| 同盟国 | tablem | Colrem |
|---|---|---|
| customer_id | 顾客 | customer_id |
| lental_id | 租金 | lental_id |
| Staff_ID | 职员 | Staff_ID |
您还可以构建程序查询。
例子:
$ results = $ pdoOne -> select ( " * " )-> from ( " producttype " )
-> where ( ' name=? ' , [ ' Cocacola ' ])
-> where ( ' idproducttype=? ' , [ 1 ])
-> toList (); 指示要返回的列。该参数是SQL命令,因此它允许数据库支持(包括功能,常数,操作员,别名等)的任何操作。
$ results = $ pdoOne -> select ( " col1,col2 " ); //...生成查询:选择COL1,COL2 ....
$ results = $ pdoOne -> select ( " select * from table " ); //->...生成查询:从表中选择 * * 。
生成一个返回值计数的查询。这是方法选择()的宏
$ result = $ pdoOne -> count ( ' from table where condition=1 ' ); // select count(*) from table where c..
$ result = $ pdoOne -> count ()-> from ( ' table ' )-> where ( ' condition=? ' ,[ 1 ]); // select count(*) from table where c..
$ result = $ pdoOne -> count ( ' from table ' , ' col1 ' ); // select count(col1) from table
$ result = $ pdoOne -> count ()-> from ( ' table ' ); // select count(*) from table生成一个查询,该查询返回列的最小值。如果$ arg为空,则使用$ sql作为列的名称,它是方法select()
$ result = $ pdoOne -> min ( ' from table where condition=1 ' , ' col ' ); // select min(col) from table where c..
$ result = $ pdoOne -> min ( ' from table ' , ' col1 ' ); // select min(col1) from table
$ result = $ pdoOne -> min ( '' , ' col1 ' )-> from ( ' table ' ); // select min(col1) from table
$ result = $ pdoOne -> min ( ' col1 ' )-> from ( ' table ' ); // select min(col1) from table生成一个查询,该查询返回列的最大值。如果$ arg为空,则使用$ sql作为列的名称,它是方法select()
$ result = $ pdoOne -> max ( ' from table where condition=1 ' , ' col ' ); // select max(col) from table where c..
$ result = $ pdoOne -> max ( ' from table ' , ' col1 ' ); // select max(col1) from table生成一个返回列的总和值的查询。如果$ arg为空,则使用$ sql作为列的名称,它是方法select()
$ result = $ pdoOne -> sum ( ' from table where condition=1 ' , ' col ' ); // select sum(col) from table where c..
$ result = $ pdoOne -> sum ( ' from table ' , ' col1 ' ); // select sum(col1) from table生成一个查询,该查询返回列的平均值。如果$ arg为空,则使用$ sql作为列的名称,它是方法select()
$ result = $ pdoOne -> avg ( ' from table where condition=1 ' , ' col ' ); // select avg(col) from table where c..
$ result = $ pdoOne -> avg ( ' from table ' , ' col1 ' ); // select avg(col1) from table生成一个选择命令。
$ results = $ pdoOne -> select ( " col1,col2 " )-> distinct (); //...生成查询:选择不同的COL1,COL2 ....
注意: - >独特('unique)返回选择唯一..
生成一个“来自” SQL命令。
$ results = $ pdoOne -> select ( " * " )-> from ( ' table ' ); //...生成查询:从表中选择 * *
$表可以是单个桌子或SQL结构。对于ExAMP,下一个命令是有效的:
$ results = $ pdoOne -> select ( " * " )-> from ( ' table t1 inner join t2 on t1.c1=t2.c2 ' ); //...生成一个命令。
$ results = $ pdoOne -> select ( " * " )
-> from ( ' table ' )
-> where ( ' p1=1 ' ); //...哪里可以以不同的方式表达。
可以编写没有参数的地方,如下所示:
$ results = $ pdoOne -> select ( " * " )-> from ( ' table ' )-> where ( " p1=1 and p2>2.5 or p3 like '%aa%' " ); $ aa = ' aa ' ;
$ results = $ pdoOne -> select ( " * " )-> from ( ' table ' )-> where ( " p1=? and p2>? or p3 like ? " ,[ 1
, 2.5
, " % $ aa % " ]);它也有效
// (if there is only a single argument without a type)
$ results = $ pdoOne -> select ( " * " )-> from ( ' table ' )-> where ( " p1=? " ,[ 1 ]); // = where("p1=?",[1]);
// (if we don't define to where to put the value)
$ results = $ pdoOne -> select ( " * " )-> from ( ' table ' )-> where ( " p1 " ,[ 1 ]); // = where("p1=?",[1]); 它是使用关联数组的查询的速记定义,其中键是列的名称,值是要比较的值
它仅适用于平等(=)和逻辑运算符'和' (该类型是自动定义的)
// select * from table where p1='1' and p2='2.5' and p3='aa'
$ results = $ pdoOne -> select ( " * " )-> from ( ' table ' )-> where ([ ' p1 ' => 1
, ' p2 ' => 2.5
, ' p3 ' => ' aa ' ]); 同样,可以指定参数的类型。
// select * from table where p1=1 and p2='2.5' and p3='aa'
$ results = $ pdoOne -> select ( " * " )-> from ( ' table ' )-> where ([ ' p1 ' =>[ 1 ]
, ' p2 ' =>[ 2.5 ]
, ' p3 ' =>[ ' aa ' ]]); 您也可以将关联数组用作参数,并在查询中命名参数
$ results = $ pdoOne -> select ( " * " )-> from ( " table " )
-> where ( ' condition=:p1 and condition2=:p2 ' ,[ ' p1 ' => ' Coca-Cola ' , ' p2 ' => 1 ])
-> toList ();生成查询:从表中选择 * *(可口可乐)和条件2 =?(1)
生成查询:从表中select * wery p1 = 1
注意:ArrayParameters是一个数组,如下:类型,值。
其中类型为i =整数,d = double,s = string或b = blob。如有疑问,请使用“ S”(请参阅表Bellow)
ArrayParameters的示例:
[1,'Hello',20.3,'World']
$ results = $ pdoOne -> select ( " * " )
-> from ( ' table ' )
-> where ( ' p1=? ' ,[ 1 ]); //...生成查询:从表中select * p1 =?(1)
$ results = $ pdoOne -> select ( " * " )
-> from ( ' table ' )
-> where ( ' p1=? and p2=? ' ,[ 1 , ' hello ' ]); //...生成查询:从表中选择 * * p1 =?(1)和p2 =?('Hello')
笔记。在哪里可以嵌套。
$ results = $ pdoOne -> select ( " * " )
-> from ( ' table ' )
-> where ( ' p1=? ' ,[ 1 ])
-> where ( ' p2=? ' ,[ ' hello ' ]); //...生成查询:从表中选择 * * p1 =?(1)和p2 =?('Hello')
您也可以使用:
$ results = $ pdoOne -> select ( " * " )-> from ( " table " )
-> where ([ ' p1 ' => ' Coca-Cola ' , ' p2 ' => 1 ])
-> toList ();生成查询:从表中选择 * * p1 =?(可口可乐)和p2 =?(1)
生成订单命令。
$ results = $ pdoOne -> select ( " * " )
-> from ( ' table ' )
-> order ( ' p1 desc ' ); //...生成查询:通过p1 desc从表顺序中选择 * *
生成组命令。
$ results = $ pdoOne -> select ( " * " )
-> from ( ' table ' )
-> group ( ' p1 ' ); //...生成查询:通过p1从表组中进行选择 *
生成一个命令。
注意:它使用与Whese()相同的参数
$ results = $ pdoOne -> select ( " * " )
-> from ( ' table ' )
-> group ( ' p1 ' )
-> having ( ' p1>? ' , array ( 1 )); //...生成查询:p1>?(1)从表组中选择 * *
注意:可以嵌套() - > ake
注意:没有参数('col> 10')没有参数
运行查询生成。
请注意,如果returnarray为true,则它将返回一个关联数组。如果returnarray为false,则返回mysqli_result
注意:它重置当前参数(例如当前选择,从哪里,哪里等)
这是rungen()的宏。如果操作失败,它将返回关联数组或false。
$ results = $ pdoOne -> select ( " * " )
-> from ( ' table ' )
-> toList (); 它从当前查询返回一个pdostatement
注意:如果要循环语句,则可以使用fetchloop()
例子:
$ stmt = $ pdoOne -> select ( " * " )
-> from ( ' table ' )
-> toPdoStatement ();
while ( $ row = $ stmt -> fetch ()) {
// do something
}它为每一行提供一个查询。
当我们不想一次阅读所有信息时,可以使用此方法,因此您可以单独阅读和处理每行
例子:
$ this -> select ( ' select id,name from table ' )
-> fetchLoop ( static function ( $ row ) { return ( $ row );}, PDO :: FETCH_ASSOC )它返回查询每一列的元(定义)。
$ results = $ pdoOne -> select ( " * " )
-> from ( ' table ' )
-> toMeta (); 或者
$ results = $ pdoOne -> toMeta ( ' select * from table ' ); 结果:
array(3) {
[0]=>
array(7) {
["native_type"]=>
string(4) "LONG"
["pdo_type"]=>
int(2)
["flags"]=>
array(2) {
[0]=>
string(8) "not_null"
[1]=>
string(11) "primary_key"
}
["table"]=>
string(11) "producttype"
["name"]=>
string(13) "idproducttype"
["len"]=>
int(11)
["precision"]=>
int(0)
}
[1]=>
array(7) {
["native_type"]=>
string(10) "VAR_STRING"
["pdo_type"]=>
int(2)
["flags"]=>
array(0) {
}
["table"]=>
string(11) "producttype"
["name"]=>
string(4) "name"
["len"]=>
int(135)
["precision"]=>
int(0)
}
}
这是Rungen的宏。它从第一列返回索引数组
$ results = $ pdoOne -> select ( " * " )
-> from ( ' table ' )
-> toListSimple (); // ['1','2','3','4'] 它返回一个关联数组,其中第一个值是密钥,第二个值是值。
如果不存在第二个值,则将索引用作值(第一个值)。
$ results = $ pdoOne -> select ( " cod,name " )
-> from ( ' table ' )
-> toListKeyValue (); // ['cod1'=>'name1','cod2'=>'name2'] 这是Rungen的宏。它返回mysqli_result或null。
$ results = $ pdoOne -> select ( " * " )
-> from ( ' table ' )
-> toResult (); // 它返回查询的第一个标量(一个值)。如果$ colname为null,则使用第一列。
$ count = $ this -> count ( ' from product_category ' )-> firstScalar ();这是Rungen的宏。它返回第一行(如果没有),则返回false,作为关联数组。
$ results = $ pdoOne -> select ( " * " )
-> from ( ' table ' )
-> first (); 这是Rungen的宏。它返回最后一行(如果有的话,如果没有,则返回false)作为关联数组。
$ results = $ pdoOne -> select ( " * " )
-> from ( ' table ' )
-> last (); 有时,运行顺序()和first()更有效,因为last()读取所有值。
它返回SQL命令和字符串。
$ sql = $ pdoOne -> select ( " * " )
-> from ( ' table ' )
-> sqlGen ();
echo $ sql ; // returns select * from table
$ results = $ pdoOne -> toList (); // executes the query注意:它不会重置查询。
有四种方法可以执行每个命令。
假设我们想在col1列中添加一个数值20
架构和值使用值列表:其中第一个值是列,第二个是值的类型(i = integer,d = double,s = string,b = blob),第二个数组包含值。
$ pdoOne -> insert ( " table "
,[ ' col1 ' ]
,[ 20 ]);同一列表中的架构和值:其中第一个值是列,第二个是值的类型(i = integer,d = double,s = string,b = blob),第三个是值。
$ pdoOne -> insert ( " table "
,[ ' col1 ' , 20 ]);模式和值使用两个关联数组:
$ pdoOne -> insert ( " table "
,[ ' col1 ' ]
,[ ' col1 ' => 20 ]);模式和值使用单个关联数组:类型是自动计算的。
$ pdoOne -> insert ( " table "
,[ ' col1 ' => 20 ]);生成一个插入命令。
$ pdoOne -> insert ( " producttype "
,[ ' idproducttype ' , ' name ' , ' type ' ]
,[ 1 , ' cocacola ' , 1 ]);使用嵌套链(单个数组)
$ pdoOne -> from ( " producttype " )
-> set ([ ' idproducttype ' , 0 , ' name ' , ' Pepsi ' , ' type ' , 1 ])
-> insert ();使用嵌套链多组
$ pdoOne -> from ( " producttype " )
-> set ( " idproducttype=? " ,[ 101 ])
-> set ( ' name=? ' ,[ ' Pepsi ' ])
-> set ( ' type=? ' ,[ 1 ])
-> insert ();或(该类型是由MySQL自动定义的)
$ pdoOne -> from ( " producttype " )
-> set ( " idproducttype=? " ,[ 101 ])
-> set ( ' name=? ' , ' Pepsi ' )
-> set ( ' type=? ' , 1 )
-> insert (); $ pdoOne -> insertObject ( ' table ' ,[ ' Id ' => 1 , ' Name ' => ' CocaCola ' ]);使用嵌套链声明集
$ pdoOne -> from ( " producttype " )
-> set ( ' (idproducttype,name,type) values (?,?,?) ' ,[ 100 , ' Pepsi ' , 1 ])
-> insert ();生成查询:插入productype(idProductType,name,type)values(?,?,?) ....
生成一个插入命令。
$ pdoOne -> update ( " producttype "
,[ ' name ' , ' type ' ] //set
,[ 6 , ' Captain-Crunch ' , 2 ] //set
,[ ' idproducttype ' ] // where
,[ 6 ]); // where $ pdoOne -> update ( " producttype "
,[ ' name ' => ' Captain-Crunch ' , ' type ' => 2 ] // set
,[ ' idproducttype ' => 6 ]); // where $ pdoOne -> from ( " producttype " )
-> set ( " name=? " ,[ ' Captain-Crunch ' ]) //set
-> set ( " type=? " ,[ 6 ]) //set
-> where ( ' idproducttype=? ' ,[ 6 ]) // where
-> update (); // update或者
$ pdoOne -> from ( " producttype " )
-> set ( " name=? " , ' Captain-Crunch ' ) //set
-> set ( " type=? " , 6 ) //set
-> where ( ' idproducttype=? ' ,[ 6 ]) // where
-> update (); // update生成查询:更新productType set
name=?,type=?idproducttype=在哪里? ...
生成删除命令。
$ pdoOne -> delete ( " producttype "
,[ ' idproducttype ' ] // where
,[ 7 ]); // where $ pdoOne -> delete ( " producttype "
,[ ' idproducttype ' => 7 ]); // where生成查询:从productType中删除的地方
idproducttype=? ...
您也可以通过DQL构建器链删除。
$ pdoOne -> from ( " producttype " )
-> where ( ' idproducttype=? ' ,[ 7 ]) // where
-> delete (); $ pdoOne -> from ( " producttype " )
-> where ([ ' idproducttype ' => 7 ]) // where
-> delete (); 生成查询:从productType中删除的地方
idproducttype=? ...
可以选择缓存查询结果。查询的持续时间也在查询中定义。如果查询的结果未缓存,则将其正常计算(在数据库中执行查询)。为了将查询识别为唯一的问题,系统将在使用查询,参数,方法和操作类型中创建的SHA256中生成一个唯一的ID(UID)。
该库不直接执行任何缓存操作,而是允许使用外部库来缓存结果。
class CacheService implements eftec IPdoOneCache {
public $ cacheData =[];
public $ cacheCounter = 0 ; // for debug
public function getCache ( $ uid , $ family = '' ) {
if ( isset ( $ this -> cacheData [ $ uid ])) {
$ this -> cacheCounter ++;
echo " using cache n" ;
return $ this -> cacheData [ $ uid ];
}
return false ;
}
public function setCache ( $ uid , $ family = '' , $ data = null , $ ttl = null ) {
$ this -> cacheData [ $ uid ]= $ data ;
}
public function invalidateCache ( $ uid = '' , $ family = '' ) {
unset( $ this -> cacheData [ $ uid ]);
}
}
$ cache = new CacheService ();(2)设置缓存服务
$ pdoOne = new PdoOne ( " mysql " , " 127.0.0.1 " , " travis " , "" , " travisdb " );
$ cache = new CacheService ();
$ $ pdoOne -> setCacheService ( $ cache );(3)使用如下的缓存,我们必须在查询的任何部分中添加usecache()方法。
$ pdoOne -> select ( ' select * from table ' )
-> useCache ()-> toList (); // cache that never expires
$ pdoOne -> select ( ' select * from table ' )
-> useCache ( 1000 )-> toList (); // cache that lasts 1000ms. class CacheService implements eftec IPdoOneCache {
public function getCache ( $ uid , $ family = '' ) {
return apcu_fetch ( $ uid );
}
public function setCache ( $ uid , $ family = '' , $ data = null , $ ttl = null ) {
apcu_store ( $ uid , $ data , $ ttl );
}
public function invalidateCache ( $ uid = '' , $ family = '' ) {
// invalidate cache
apcu_delete ( $ uid );
}
}
$ cache = new CacheService ();序列是auto_numeric(身份)字段的替代方法。它具有创建序列的两种方法:雪花和序列。它主要是因为它返回一个数字是一种替代方法(GUID通常是索引和存储更昂贵的字符串)
序列的目的是创建一个从未重复的唯一数字。
$ dao -> nodeId = 1 ; // optional
$ dao -> tableSequence = ' snowflake ' ; // optional
$ dao -> createSequence (); // it creates a table (and it could create a store procedure) called snowflake and a function called next_snowflake(). You could create it only once.可以创建一个没有任何表的新序列。它很快,但是可能会遇到碰撞问题。
它仅在我们不执行超过一个0.0001秒操作的情况下确保无碰撞数字,但是,它还添加了一个伪随机数(及时基于0-4095),因此碰撞的机会为1/4095 (每两个操作每两个操作每0.0001秒进行)。它基于Twitter的雪花号码。 IE。如果您每秒进行少于100万次操作(从技术上讲:4500万),则可以安全碰撞。
$ pDO-> getSequencePhp([unrephictable = false])在不使用表的情况下返回序列。该顺序比$ dao-> get序列更有效,但是它使用随机值来处理碰撞。
如果上升是正确的,那么它将返回一个不可预测的数字(它翻转一些数字)
$ pdo -> getSequencePHP () // string(19) "3639032938181434317" $ dao -> getSequencePHP ( true ) // string(19) "1739032938181434311" $ pdo ->getSequence() // string(19) "3639032938181434317"
$ pdo -> getSequencePHP () // string(19) "3639032938181434317" $ pdo -> getSequence ( true ) // returns a sequence by flipping some values.
$ pdo -> getSequencePHP ( true ) // string(19) "1739032938181434311" | 场地 | 描述 | 例子 |
|---|---|---|
| $ prefixbase | 如果我们需要在每个表中添加一个前缀 | $ this-> prefixbase ='example_'; |
| $ InternalCacheCounter | 内部缓存命中的计数器。 | $ this-> internalCacheCounter =; |
| $ nodeid | 由序列(雪花)使用。 nodeid是节点的标识符。它必须在0..1023之间 | $ this-> nodeid = 3; |
| $ tablesequence | 桌子序列的名称(雪花) | $ this-> tablesequence =“ tableseq1”; |
| $ masks0 | 如果我们要生成一个不可预测的数字(按序列使用) | $ this-> maskS0 = [0,1,2,3,4]; |
| $ masks1 | 如果我们要生成一个不可预测的数字(按序列使用) | $ this-> masks1 = [4,3,2,1,0]; |
| $ databaseType | 当前类型的数据库。它是通过EL构造器设置的 | echo $ this-> databaseType; |
| $服务器 | 当前的服务器机器 | echo $ this->服务器; |
| $用户 | 当前用户 | echo $ this->用户; |
| $ PWD | 当前密码 | Echo $ this-> pwd; |
| $ db | 当前数据库或模式(Oracle忽略此值) | echo $ this-> dB; |
| $ charset | 设置默认字符集。必须通过构造函数设置 | echo $ this-> charset; |
| $ iSopen | 如果数据库否则连接,则是错误的,这是错误的 | 如果($ this-> iSopen){…}; |
| $ throwonError | 如果是true(默认),则如果发生错误,则会引发错误。如果是错误的,则执行继续 | $ this-> throwonError = false; |
| $ conn1 | PDO的实例。您可以设置或直接使用它。 | $ this-> conn1-> pdostatement(..); |
| $ TransactionOpen | 如果交易开放,则为true | 如果($ this-> transactionopen){…}; |
| $ readonly | 如果数据库仅读取模式。如果为tum,那么我们必须避免在数据库中写入 | $ this-> readonly = true; |
| $ logfile | 日志文件的完整文件名。如果是空的,则不会存储日志文件。日志文件仅限于1MB | $ this-> logFile =“/folder/file.log”; |
| $ errortext | 它存储最后一个错误。 Runget和快捷店重置 | echo $ this-> errortext; |
| $ isthrow | 托多 | $ this-> isthrow =; |
| $ loglevel | 它指示当前日志级别。 0 =无日志(用于生产),3 =完整日志 | $ this-> loglevel = 3; |
| $ LastQuery | 执行最后查询 | Echo $ this-> LastQuery; |
| $ LASTPARAM | 最后一个参数。这是一个关联阵列 | echo $ this-> lastparam; |
该库允许对信息的加密/解密。
要设置加密,您可以使用下一个命令:
$ this -> setEncryption ( 12345678 , '' , ' INTEGER ' ); // the type of encryption is integer and it only works with integers. It doesn't use a salt value
$ this -> setEncryption ( ' password ' , ' some-salt ' , ' AES-256-CTR ' ); // the password, the salt and the type of encryption (aes-256-ctr), you can use other methods
$ this -> setEncryption ( ' passwrd ' , '' , ' SIMPLE ' ); // the type of encryption is simple and it only works with primitive values. It doesn't use a salt.然后,您可以使用
$ encrypted = $ this -> encrypt ( $ original ); // encrypt $original
$ original = $ this -> decrypt ( $ encrypted ); // decrypt $encrypted例子:
$ this -> setEncryption ( ' 12345 ' , ' salt-1234 ' ); // it will use AES-256-CTR, the password and the salt must be secret.
// create user
$ this -> set ([ ' username ' => 1 , ' password ' => $ this -> encrypt ( $ password )])
-> from ( ' user ' )
-> insert ();
// validate user
$ user = $ this -> select ([ ' username ' , ' password ' ])
-> from ( ' user ' )
-> where ([ ' username ' , ' password ' ],[ 1 , $ this -> encrypt ( $ password )])
-> first ();
// $user= if false or null then the user does not exist or the password is incorrect. 您可以将日志级别设置为3。当操作失败时,日志级别工作,日志级别越高,则显示大多数信息。
$ pdoOne -> logLevel = 3 ; // the highest for debug.默认情况下,PDOONE会引发PHP错误,但是我们可以通过将字段$ throwoneror设置为false来避免。
$ pdoOne -> throwOnError = false ; // it could be used in production. var_dump ( $ pdoOne -> lastQuery ); // it shows the last query
var_dump ( $ pdoOne -> lastParam ); // and it shows the last parameters.如果空,则不会生成日志文件(使用PHP日志文件)
$ pdoOne -> logFile = true ; Pdoone仅在CLI中可用一些功能。

执行下一行(在LIB文件夹中)
php pdoonecli.php
(或指向正确的文件夹)
php/var/web/供应商/eftec/lib/pdoonecli
您可以使用标志“ -i”以在交互式模式下输入。
您可以使用Tab键自动完成值(如果有)。

注意:您还可以保存和加载配置。
连接到MySQL并从表“ Actor”中生成CSV
# # via arguments
php pdoonecli --databasetype mysql --server 127.0.0.1 -u root -p abc.123 --database sakila -in actor -out csv
# # via user input (interactive)
php pdoonecli -i -in actor -out csv将配置保存在文件中
php pdoonecli --databasetype mysql --server 127.0.0.1 -u root -p abc.123 --database sakila --saveconfig myconfig从文件加载配置
php pdoonecli --loadconfig myconfig -in actor -out csv您可以使用标志“ -cli”来生成存储库类

CLI是交互式的,它允许加载和保存配置。
该功能将生成现成的存储库类。
假设下一个例子
mysql:
php pdoone.php-数据库mysql-服务器127.0.0.1:3306 - 用户root -p abc.123 -db sakila -input sakila-输入“ actor” - 输出classcode
SQLSRV:
php pdoone.php-数据库SQLSRV -Server PCJC SQLEXPRESS - 用户SA -P ABC.123 -DB Sakila -Input“ Actor” - Output classcode
它将连接到数据库MySQL,IP:127.0.0.1和数据库Sakila,它将读取“ Actor”表。
它将返回下一个结果
/**
* Generated by PdoOne Version 1.28
* Class ActorRepo
*/
class ActorRepo
{
const TABLE = ' Actor ' ;
const PK = ' actor_id ' ;
/** @var PdoOne */
public static $ pdoOne = null ;
/**
* It creates a new table<br>
* If the table exists then the operation is ignored (and it returns false)
*
* @param array $definition
* @param null $extra
*
* @return array|bool|PDOStatement
* @throws Exception
*/
public static function createTable ( $ definition , $ extra = null ) {
if (! self :: getPdoOne ()-> tableExist ( self :: TABLE )) {
return self :: getPdoOne ()-> createTable ( self :: TABLE , $ definition , self :: PK , $ extra );
}
return false ; // table already exist
}
// .....
}此功能将生成一个新的存储库类,其中最常见的操作:插入,列表,更新,删除,get,count,Count,Create Table,Drop Table和Druncate Table
为什么我们需要生成课? (而不是继承一个)这个crud类只是一个起点。开发人员可以修改代码,添加新方法,修改上一个方法等。
对于使用该类,我们可以编写下一个代码:
// 1) option 1, inject an instance of $pdo
ActorRepo:: setPdoOne ( $ pdoOne ); // it inject the current connect to the database
// 2) option 2.
// If the global variable $pdoOne exists, then it is injected. (unless it is defined by using setPdoOne()
$ pdoOne = new PdoOne ( " mysql " , " 127.0.0.1 " , " root " , " abc.123 " , " sakila " , "" );
$ pdoOne -> connect ();
// 3) option 3
// If the global function pdoOne() exists, then it is used for obtain the instance.
function pdoOne () {
global $ pdo ;
if ( $ pdo === null ) {
$ pdo = new PdoOne ( ' mysql ' , ' 127.0.0.1 ' , ' root ' , ' abc.123 ' , ' sakila ' );
}
return $ pdo ;
}
$ actorActorRepo :: get ( 2 ); // it will read the actor with the pk=2 and it will return as an array.
$ actors = $ actorArray =ActorRepo:: select (); // it returns all the rows.另外,您可以自动生成PHP文件,如下所示:
php pdoone.php -database mysql -Server 127.0.0.0.1:3306 -user root -pwd abc.123 -db sakila -input -input“ actor” actor“ -output classcode> actorrepo.phpo.phppo.phppo.phppo.phppo
注意:代码缺乏PHP标签,名称空间和使用,但其他所有内容都在这里。
它将进行查询,并使用查询格式返回PHP代码。
例子:
php pdoone.php -database mysql -Server 127.0.0.0.1:3306 -user root -pwd abc.123 -db sakila -unput -input“ select * select * select * from actor” -output Selectcode
它将生成下一个代码:
/** @var array $result=array(["actor_id"=>0,"first_name"=>'',"last_name"=>'',"last_update"=>'']) */
$ result = $ pdo
-> select ( " * " )
-> from ( " actor " )
-> toList ();它将在选定的查询或表中生成一个关联数组(默认值)。
php pdoone.php -database mysql -Server 127.0.0.0.1:3306 -user root -pwd abc.123 -db sakila -unput -input“ select * select * select * from actor” -output arraycode
它将返回:
// ["actor_id"=>0,"first_name"=>'',"last_name"=>'',"last_update"=>'']它将返回查询结果作为JSON
php pdoone.php -database mysql -Server 127.0.0.0.1:3306 -user root -pwd abc.123 -db sakila -input -input“ select * select * select * from actor” -output json
它将返回:
[{ "actor_id" : " 1 " , "first_name" : " PENELOPE " , "last_name" : " GUINESS " , "last_update" : " 2006-02-15 01:34:33 " }
,{ "actor_id" : " 2 " , "first_name" : " NICK " , "last_name" : " WAHLBERG " , "last_update" : " 2006-02-15 01:34:33 " }
,{ "actor_id" : " 3 " , "first_name" : " ED " , "last_name" : " CHASE " , "last_update" : " 2006-02-15 01:34:33 " }
,{ "actor_id" : " 4 " , "first_name" : " JENNIFER " , "last_name" : " DAVIS " , " last_update " }]它将返回查询结果作为JSON
php pdoone.php -database mysql -Server 127.0.0.0.1:3306 -user root -pwd abc.123 -db sakila -unput -input“ select * select * select * from actor” -output CSV
它将返回:
actor_id,first_name,last_name,last_update
1,"PENELOPE","GUINESS","2006-02-15 01:34:33"
2,"NICK","WAHLBERG","2006-02-15 01:34:33"
3,"ED","CHASE","2006-02-15 01:34:33"
4,"JENNIFER","DAVIS","2006-02-15 01:34:33"
或者,与CLI相比,该库具有接口视觉效果。它可以完成CLI的所有操作。

只需调用方法渲染()
<?php
use eftec PdoOne ;
use mapache_commons Collection ;
include " ../vendor/autoload.php " ;
$ dao = new PdoOne ( " test " , " 127.0.0.1 " , " dummy " , " dummy " , " dummy " ); // we need any connection.
$ dao -> logLevel = 3 ;
$ dao -> render ();文件夹示例/testui.php中有一个示例
下一个命令通常是单独执行的(不是在方法链中)
| 方法 | 描述 | 例子 |
|---|---|---|
| cretetable() | 使用存储库中的定义创建表格和索引 | tablaparentrepo :: createTable(); |
| createforeignkeys() | 创建桌子的所有外键 | TablaparentRepo :: CreateForeignKeys(); |
| droptable() | 丢下桌子 | TablaparentRepo :: Droptable(); |
| 截短() | 截断表 | tablaparentrepo :: truncate(); |
| 有效table() | 验证桌子是否没有更改 | $ ok = tablaparentrepo :: valiveTable(); |
TablaParentRepo:: createTable ();
TablaParentRepo:: createForeignKeys ();
TablaParentRepo:: dropTable ();
TablaParentRepo:: truncate ();
// We don't have a method to alter a table.
$ ok =TablaParentRepo:: validTable (); // it returns true if the table matches with the definition stored into the clas嵌套运算符是我们方法链之间应介绍的方法。
classRepo :: op():: where():: finalop()为✅
classrepo :: op():: op():: where()将使链条打开
例如:
// select *
// from table
// inner join table2 on t1=t2
// where col=:arg
// and col2=:arg2
// group by col
// having col3=:arg3
// order by col
// limit 20,30
$ results = $ pdo -> select ( ' * ' )
-> from ( ' table ' )
-> innerjoin ( ' table2 on t1=t2 ' )
-> where ( ' col=:arg and col2:=arg2 ' ,[ 20 , 30 ])
// it also works with ->where('col=:arg',20)->where('col2'=>30)
// it also works with ->where('col=?',20)->where('col2=?'=>30)
-> group ( ' col ' )
-> having ( ' col3=:arg3 ' , 400 )
-> order ( ' col ' )
-> limit ( ' 20,30 ' )
-> toList (); // end of the chain| 方法 | 描述 | 例子 |
|---|---|---|
| 在哪里() | 它在链条上增加了一个 | tablaparentrepo :: where() |
| 命令() | 它向链条添加了订单 | tablaparentrepo :: order() |
| 团体() | 它增加了一个链条 | tablaparentrepo :: group() |
| 限制() | 它限制了结果 | tablaparentrepo :: limit() |
| 页() | 它类似于限制,但使用页面 | tablaparentrepo :: page() |
| Innerjoin() | 它在查询中添加了内心连接 | tablaparentrepo :: innerjoin() |
| 左边() | 它在查询中添加了一个左键 | tablaparentrepo :: left() |
| 正确的() | 它为查询添加了正确的加入 | tablaparentrepo :: right() |
我们有不同的方法来在数据库中生成DQL(QUERY)命令。
如果操作失败,他们会返回一个错误,并且可能会触发异常。
下一个方法应在链的末端。示例:
classRepo :: op():: op():: tolist()为✅
classrepo :: op():: tolist():: op()将触发异常
| 命令 | 描述 | 例子 |
|---|---|---|
| tolist() | 返回一系列元素 | $ data = tablenamerepo :: tolist(); //从tablerepo中选择 * $ data = tablenamerepo :: where('a1 =?',[$ value]):: tolist(); //从tablerepo中选择 * a1 = $ value |
| 第一的() | 返回一个简单的行 | $ data = tablenamerepo :: first($ pk); //从tablerepo中选择 * pk = $ pk(它总是返回1或零值) $ data = tablenamerepo :: where('a1 =?',[$ value]):: first(); //它返回第一个值(或错误如果找不到的话) |
| 存在() | 如果存在主键,则返回true | $ data = tablenamerepo ::存在($ pk); //如果对象存在,则返回true。 |
| 数数() | 返回查询中的行数 | $ data = tablenamerepo :: count($条件); $ data = tablenamerepo :: where('a1 =?',[$ value]):: count(); |
下一个方法允许在数据库中插入,更新或删除值。
| 方法 | 描述 | 例子 |
|---|---|---|
| 插入 | 它将值插入数据库。它可以返回身份 | $ IDENTITY = TablaparentRepo :: insert($ obj); |
| 更新 | 它将值更新到数据库中。 | tablaparentrepo ::更新($ obj); |
| 删除 | 它从数据库中删除一个值。 | tablaparentrepo :: delete($ obj); |
| DeleteByid | 它从数据库中删除一个值(使用主键作为条件)。 | TablaparentRepo :: DeleteById($ pk); |
// where obj is an associative array or an object, where the keys are the name of the columns (case sensitive)
$ identity =TablaParentRepo:: insert ( $ obj );
TablaParentRepo:: update ( $ obj );
TablaParentRepo:: delete ( $ obj );
TablaParentRepo:: deleteById (id);可以验证模型。使用数据库的信息,使用列的类型,长度,如果值允许null以及是否为识别(自动数字),则使用数据库的信息进行验证。
$ obj =[ ' IdUser ' => 1 , ' Name ' ='John Doe'];
UserRepo:: validateModel ( $ obj , false ,[ ' _messages ' ]); // returns true if $obj is a valid User.递归阵列是一个可以读取或获得或比较的值的字符串阵列。例如,有条件地加入表。 Pdoone不直接使用它,而是_basepdoonerepo使用它(_basepdoonerepo是当我们自动生成存储库服务类时使用的类)。
例子
$ this -> select ( ' * ' )-> from ( ' table ' )-> recursive ([ ' table1 ' , ' table1.table2 ' ]);
// some operations that involves recursive
if ( $ this -> hasRecursive ( ' table1 ' )) {
$ this -> innerJoin ( ' table1 on table.c=table1.c ' );
}
if ( $ this -> hasRecursive ( ' table1.table2 ' )) {
$ this -> innerJoin ( ' table1 on table1.c=table2.c ' );
}
$ r = $ this -> toList (); // recursive is resetted. 它设置了递归数组。
每次链方法结束时,都会重置此值。
它得到递归数组。
如果递归有一些针,它将返回真实。
如果$ this->递归为['*'],那么它总是返回true。
$ this -> select ( ' * ' )-> from ( ' table ' )-> recursive ([ ' * ' ]);
$ this -> hasRecursive ( ' anything ' ); // it always returns true. | 图书馆 | 插入 | findpk | 水合 | 和 | 时间 |
|---|---|---|---|---|---|
| PDO | 671 | 60 | 278 | 887 | 3,74 |
| pdoone | 774 | 63 | 292 | 903 | 4,73 |
| Lessql | 1413 | 133 | 539 | 825 | 5,984 |
| Yiim | 2260 | 127 | 446 | 1516年 | 8,415 |
| yiimwithcache | 1925年 | 122 | 421 | 1547年 | 7,854 |
| yii2m | 4344 | 208 | 632 | 1165 | 11,968 |
| YII2 -Marraydrate | 4114 | 213 | 531 | 1073 | 11,22 |
| YII2MScalarydrate | 4150 | 198 | 421 | 516 | 9,537 |
| Propel20 | 2507 | 123 | 1373 | 1960年 | 11,781 |
| Propel20WithCache | 1519年 | 68 | 1045 | 1454 | 8,228 |
| propel20formatondemand | 1501 | 72 | 994 | 1423 | 8,228 |
| 学分 | 2119 | 250 | 1592年 | 1258 | 18,139 |
| doctrinemwithcache | 2084 | 243 | 1634年 | 1155 | 17,952 |
| doptrinemarrayhydrate | 2137 | 240 | 1230 | 877 | 16,83 |
| 学分扫描剂 | 2084 | 392 | 1542 | 939 | 18,887 |
| doctrinemwithoutproxies | 2119 | 252 | 1432 | 1960年 | 19,822 |
| 雄辩 | 3691 | 228 | 708 | 1413 | 12,155 |
PDOONE在PDO上增加了一些Ovehead,但是它简单地包装了PDO。
这意味着您已更新PDOONE,并且正在使用ORM生成的一个类。该课程必须重新生成。
简而言之:
每个主要版本都意味着它可能会破坏旧的代码。 IE 1.0-> 2.0
每个次要版本都意味着它添加了一个新功能,即1.5-> 1.6(新方法)
每个十进制版本都意味着它可以修补/修复/重构以前的功能IE 1.5.0-> 1.5.1(fix)
4.10 2024-09-06
4.9.2 2024-08-20
4.9.1 2024-08-20
4.9 2024-08-02
4.8 2024-07-06
4.7.1 2024-06-07
4.7 2024-06-07
4.6.2 2024-03-02
4.6.1 2024-03-02
4.6 2024-03-02
4.4 2023-12-12
4.3.3 2023-09-05
4.3.2 2023-09-05
4.3.1 2023-09-02
4.3 2023-07-01
4.2 2023-04-07
4.1.2 2023-03-21
4.1.1 2023-03-21
4.1 2023-03-20
4.0.1 2023-03-11
4.00 2023-11-03
3.16 2023-12-02
3.15 2023-02-03
3.14 2023-01-30
3.13 2023-01-26
3.12.2 2022-09-03
3.12.1 2022-08-26
3.12 2022-08-14
3.11.1 2022-07-30
3.11 2022-07-30
3.10 2022-07-30
3.9 2022-07-23
3.8.1 2022-07-23
3.8 2022-07-22
3.7 2022-07-16
3.6 2022-07-07
3.5 2022-07-06
3.3 2022-06-27
3.2 2022-06-27
3.1.6 2022-06-24
3.1.5 2022-06-23
3.1.4 2022-06-21
3.1.3 2022-06-18
3.1.2 2022-06-18
3.1.1 2022-06-17
3.1 2022-06-11
3.0 2022-06-1
2.32 2022-03-20
2.31 2022-03-04
2.30 2022-02-28
2.29 2022-02-20
2.27 2022-02-19
2.26 2022-02-19
2.25 2022-02-01
2.24.1 2022-02-06
2.24 2022-02-06
2.23 2022-02-04
2.22.2 2022-02-01
2.22.1 2022-01-03
2.22 2022-01-30
2.21 2022-01-28
However, it is far from perfect.
2.20 2022-01-04
2.19
2.18
2.16
2.15 2021-07-24
2.14.3 2021-06-15
2.14.2 2021-06-13
2.14.1 2021-06-09
2.14 2021-06-04
_BasePdoOneRepo now works more closely with the class PdoOneQuery , so each query is a different instance.
[fix] PdoOne dateConvertInput() does not crash when the value is not a date.
[fix] PdoOne throwError() does not stack errors but still triggers the last error (if any).
[changes] ❗ PdoOne aggregate functions (sum,min,max,avg) now returns a value instead of generating a query.
$result=$pdo->sum('xxx')->firstScalar(); // before $result=$pdo->sum('xxx'); // 现在
[fix] PdoOne generateCodeArray() used for the generation of classes, returns the correct name when it is set.
[changes] _BasePdoOneRepo : reset(),getQuery(),dropTable(),useCache(),limit(),newQuery(),order(),innerjoin(),left() ,right()
[changes] PdoOneQuery : Multiples changes.
2.13.1 2021-05-22
2.13 2021-04-17
2.12 2021-04-17
2.11.1 2021-04-17
2.11 2021-04-17
2.10.3 2021-04-14
2.10.2 2021-04-06
2.10.1 2021-04-05
2.10 2021-04-04
2.9.4 2021-03-22
2.9.3 2021-02-22
2.9.2 2021-02-18
2.9.1 2021-02-16
2.9 2021-02-16
2.8 2021-02-13
2.7.1 2021-01-21
2.7 2021-01-10
2.6.3 2020-10-16
2.6.2 2020-10-09
2.6.1 2020-09-24
2.6 2020-09-17
2.5 2020-09-13
2.4.1 2020-09-13
2.4 2020-09-06
2.3 2020-09-06
2.2.6 2020-09-03
2.2.5 2020-08-30
2.2.3 2020-08-23
2.2.2 2020-08-17
2.2.1 2020-08-16
2.2 2020-08-14
$ this -> setUseInternalCache ( true );
$ rows = $ this -> select ( ' * ' )-> from ( ' table ' )-> where ([ ' i ' => 1 ])-> toList (); // read from the database
// ...
$ rows2 = $ this -> select ( ' * ' )-> from ( ' table ' )-> where ([ ' i ' => 1 ])-> toList (); // read from memory
// ...
$ rows3 = $ this -> select ( ' * ' )-> from ( ' table ' )-> where ([ ' i ' => 2 ])-> toList (); // read from the database because the query is in
// memory but the parameters are different
echo $ this -> internalCacheCounter ; The internal cache is tested with runRawQuery (if returns an array), toList(), meta() and first()
2.0.1 2020-08-12
2.0 2020-08-11
1.55.1 2020-08-05
1.55 2020-8-05
1.54 2020-8-02
1.53 2020-7-27
1.52 2020-7-19
1.51 2020-7-18
1.50 2020-7-04
1.49 2020-6-19
1.48 2020-6-15
1.47 2020-6-14
1.46 2020-6-13
1.45.1 2020-6-11
1.45 2020-6-7
1.44.2 2020-6-3
1.44.1 2020-6-2
1.44 2020-5-31
1.43 2020-5-31
1.42 2020-5-29
1.41.2 2020-5-29
1.41.1 2020-5-28
1.41 2020-5-28
1.40.1 2020-5-27
1.40 2020-05-21
1.39 2020-05-12
1.38 2020-05-10
1.37 2020-05-03
1.36 2020-05-03
1.35.1 2020-04-30
1.35 2020-04-28
1.34.2 2020-04-27
1.34.1 2020-04-27
1.34 2020-04-27
1.33 2020-04-15
1.32.1 BasePdoOneRepo added version 2.0
1.32 2020-04-12
1.31.1 2020-04-11
1.31 2020-04-11
1.30 2020-04-10
1.29 2020-04-10
1.28.1 2020-04-06
1.28 2020-04-06
1.24 2020-03-26
1.23.1 2020-03-10
1.23 2020-03-10
1.22 2020-02-08
1.21 2020-02-07
1.20 2020-jan-25
1.19 2020-jan-15
1.16 2020-jan-14
1.15 2019-dec-29
1.14 2019-dec-26
1.13 2019-dec-26
1.12 2019-oct-20 Added argument (optional) ->toList($pdomodel) Added method ->toListSimple()
1.11 2019-oct-01 1.11 It is still compatible with php 5.6.Added to composer.json
1.10 2019-oct-01 1.10 Added method dateConvert(). Added trace to the throw.
1.9 2019-aug-10 1.8 republished
1.8 2019-aug-10 Added a date format. Methods dateSql2Text() and dateText2Sql()
1.7 2019-jun-23 Added some benchmark. It also solves a problem with the tags. Now: table.field=? is converted to table . field =?
1.6 2019-jun-22 affected_rows() returns a correct value.
1.5 2019-may-31 some cleanups. columnTable() returns if the column is nullable or not.
1.4 2019-may-30 insertobject()
1.3 2019-may-23 New changes
1.2 2019-may-22 New fixed.
1.1 2019-may-21 Some maintenance
1.0 2019-may-21 First version