摘要:查詢語(yǔ)言查詢語(yǔ)言,簡(jiǎn)稱或,是一種面向?qū)ο蟮母呒?jí)語(yǔ)言,允許用標(biāo)準(zhǔn)化的編寫。該對(duì)象的每個(gè)成員都是一個(gè)包含所查詢字段的標(biāo)準(zhǔn)對(duì)象。
Phalcon查詢語(yǔ)言(Phalcon Query Language)
Phalcon查詢語(yǔ)言,簡(jiǎn)稱PhalconQL或PHQL,是一種面向?qū)ο蟮母呒?jí)SQL語(yǔ)言,允許用標(biāo)準(zhǔn)化的SQL編寫。PHQL實(shí)現(xiàn)了把操作語(yǔ)句解析為RDBMS目標(biāo)語(yǔ)言的解析器(C語(yǔ)言編寫)。
為了達(dá)到最佳性能,Phalcon提供了與SQLite相同的解析器,其線程安全,內(nèi)存占用極低。
解析器先檢查傳遞的PHQL語(yǔ)句的語(yǔ)法,然后構(gòu)建中間語(yǔ)句,最后將其轉(zhuǎn)換為RDBMS對(duì)應(yīng)的SQL語(yǔ)句。
PHQL實(shí)現(xiàn)了一系列功能,可以更安全的操作數(shù)據(jù)庫(kù)。
參數(shù)綁定是PHQL功能之一,使代碼更安全
PHQL每次只允許執(zhí)行一條SQL語(yǔ)句,以防SQL注入
PHQL會(huì)忽略所有SQL注入中常用的SQL注釋
PHQL只允許數(shù)據(jù)操作語(yǔ)句,避免錯(cuò)誤的或未經(jīng)授權(quán)的更改、刪除數(shù)據(jù)庫(kù)和表
PHQL實(shí)現(xiàn)了高級(jí)抽象接口,允許以模型方式操作表,以類屬性方式操作表字段
使用示例(Usage Example)為了更好的解釋PHQL工作原理,請(qǐng)參考下例。有Cars和Brands兩個(gè)模型:
belongsTo("brand_id", "Brands", "id"); } }
每輛車都屬于一個(gè)品牌,每個(gè)品牌有多輛車:
hasMany("id", "Cars", "brand_id"); } }創(chuàng)建PHQL查詢(Creating PHQL Queries)
實(shí)例化PhalconMvcModelQuery類即可創(chuàng)建PHQL查詢:
getDI() ); // 執(zhí)行查詢,返回結(jié)果(如果有的話) $cars = $query->execute();
控制器或視圖中,使用PhalconMvcModelManager可以很容易的創(chuàng)建、執(zhí)行PHQL查詢:
modelsManager->createQuery("SELECT * FROM Cars"); $cars = $query->execute(); // 使用參數(shù)綁定 $query = $this->modelsManager->createQuery("SELECT * FROM Cars WHERE name = :name:"); $cars = $query->execute( [ "name" => "Audi", ] );
或者直接執(zhí)行查詢:
modelsManager->executeQuery( "SELECT * FROM Cars" ); // 使用參數(shù)綁定 $cars = $this->modelsManager->executeQuery( "SELECT * FROM Cars WHERE name = :name:", [ "name" => "Audi", ] );查詢記錄(Selecting Records)
PHQL允許使用我們熟知的SELECT語(yǔ)句查詢記錄,使用模型名字代替表名:
createQuery( "SELECT * FROM Cars ORDER BY Cars.name" ); $query = $manager->createQuery( "SELECT Cars.name FROM Cars ORDER BY Cars.name" );
允許帶命名空間的模型名:
createQuery($phql); $phql = "SELECT FormulaCars.name FROM FormulaCars ORDER BY FormulaCars.name"; $query = $manager->createQuery($phql); $phql = "SELECT c.name FROM FormulaCars c ORDER BY c.name"; $query = $manager->createQuery($phql);
PHQL支持大部分標(biāo)準(zhǔn)SQL語(yǔ)法,非標(biāo)準(zhǔn)的SQL語(yǔ)法也同樣支持,如LIMIT:
createQuery($phql);結(jié)果集類型(Result Types)
結(jié)果集類型根據(jù)我們查詢字段的不同而不同,如果檢索單個(gè)完整對(duì)象,則返回PhalconMvcModelResultsetSimple對(duì)象。這種結(jié)果集是一組完整的模型對(duì)象:
executeQuery($phql); foreach ($cars as $car) { echo "Name: ", $car->name, " "; }
下面這種方式也一樣:
"name", ] ); foreach ($cars as $car) { echo "Name: ", $car->name, " "; }
完整模型對(duì)象中的數(shù)據(jù)能夠被修改,并重新保存到數(shù)據(jù)庫(kù)中,因?yàn)樗鼈兇黻P(guān)聯(lián)表的完整記錄。下面這種查詢方式不會(huì)返回完整模型對(duì)象:
executeQuery($phql); foreach ($cars as $car) { echo "Name: ", $car->name, " "; }
我們僅僅查詢了表中的某些字段,雖然返回的結(jié)果集仍然是PhalconMvcModelResultsetSimple對(duì)象,但不能當(dāng)成完整模型對(duì)象。該對(duì)象的每個(gè)成員都是一個(gè)包含所查詢字段的標(biāo)準(zhǔn)對(duì)象。
這些不表示完整對(duì)象的值就是我們所說(shuō)的標(biāo)量,PHQL允許查詢所有類型的標(biāo)量:字段,函數(shù),字面兩,表達(dá)式等:
execute($phql); foreach ($cars as $car) { echo $car->id_name, " "; }
我們可以查詢完整對(duì)象或標(biāo)量,也可以同時(shí)查詢它們:
executeQuery($phql);
這種情況下的結(jié)果集是一個(gè)PhalconMvcModelResultsetComplex對(duì)象,可以同時(shí)訪問(wèn)完整對(duì)象和標(biāo)量:
cars->name, " "; echo "Price: ", $row->cars->price, " "; echo "Taxes: ", $row->taxes, " "; }連接(Joins)
使用PHQL可以很容易的從多個(gè)模型請(qǐng)求記錄,支持大部分的JOIN方式。我們?cè)谀P椭卸x關(guān)系之后,PHQL會(huì)自動(dòng)添加這些條件:
executeQuery($phql); foreach ($rows as $row) { echo $row->car_name, " "; echo $row->brand_name, " "; }
默認(rèn)使用INNER JOIN,可以指定JOIN類型:
executeQuery($phql); $phql = "SELECT Cars.*, Brands.* FROM Cars LEFT JOIN Brands"; $rows = $manager->executeQuery($phql); $phql = "SELECT Cars.*, Brands.* FROM Cars LEFT OUTER JOIN Brands"; $rows = $manager->executeQuery($phql); $phql = "SELECT Cars.*, Brands.* FROM Cars CROSS JOIN Brands"; $rows = $manager->executeQuery($phql);
也可以手動(dòng)設(shè)置JOIN條件:
executeQuery($phql);
如果查詢中為模型定義別名,則將使用別名為結(jié)果集中的每一條記錄命名:
executeQuery($phql); foreach ($rows as $row) { echo "Car: ", $row->c->name, " "; echo "Brand: ", $row->b->name, " "; }
如果連接模型與from之后的模型具有多對(duì)多關(guān)系時(shí),中間模型將隱式的添加到查詢中:
modelsManager->executeQuery($phql);
上述代碼在MySQL中執(zhí)行下列SQL:
SELECT `artists`.`name`, `songs`.`name` FROM `artists` INNER JOIN `albums` ON `albums`.`artists_id` = `artists`.`id` INNER JOIN "songs" ON `albums`.`songs_id` = `songs`.`id` WHERE `artists`.`genre` = "Trip-Hop"聚合(Aggregations)
下面例子展示了PHQL中如何使用聚合:
executeQuery($phql)->getFirst(); echo $row["summatory"]; // 每個(gè)品牌下的汽車總數(shù) $phql = "SELECT Cars.brand_id, COUNT(*) FROM Cars GROUP BY Cars.brand_id"; $rows = $manager->executeQuery($phql); foreach ($rows as $row) { echo $row->brand_id, " ", $row["1"], " "; } // 每個(gè)品牌下的汽車總數(shù) $phql = "SELECT Brands.name, COUNT(*) FROM Cars JOIN Brands GROUP BY 1"; $rows = $manager->executeQuery($phql); foreach ($rows as $row) { echo $row->name, " ", $row["1"], " "; } $phql = "SELECT MAX(price) AS maximum, MIN(price) AS minimum FROM Cars"; $rows = $manager->executeQuery($phql); foreach ($rows as $row) { echo $row["maximum"], " ", $row["minimum"], " "; } // 統(tǒng)計(jì)品牌數(shù)量 $phql = "SELECT COUNT(DISTINCT brand_id) AS brandId FROM Cars"; $rows = $manager->executeQuery($phql); foreach ($rows as $row) { echo $row->brandId, " "; }條件(Conditions)
條件能讓我們過(guò)濾想要查詢的記錄,WHERE子句允許這樣:
executeQuery($phql); $phql = "SELECT * FROM Cars WHERE Cars.price > 10000"; $cars = $manager->executeQuery($phql); $phql = "SELECT * FROM Cars WHERE TRIM(Cars.name) = "Audi R8""; $cars = $manager->executeQuery($phql); $phql = "SELECT * FROM Cars WHERE Cars.name LIKE "Ferrari%""; $cars = $manager->executeQuery($phql); $phql = "SELECT * FROM Cars WHERE Cars.name NOT LIKE "Ferrari%""; $cars = $manager->executeQuery($phql); $phql = "SELECT * FROM Cars WHERE Cars.price IS NULL"; $cars = $manager->executeQuery($phql); $phql = "SELECT * FROM Cars WHERE Cars.id IN (120, 121, 122)"; $cars = $manager->executeQuery($phql); $phql = "SELECT * FROM Cars WHERE Cars.id NOT IN(430, 431)"; $cars = $manager->executeQuery($phql); $phql = "SELECT * FROM Cars WHERE Cars.id BETWEEN 1 AND 100"; $cars = $manager->executeQuery($phql);
此外,作為PHQL的一部分,參數(shù)綁定會(huì)自動(dòng)轉(zhuǎn)義輸入數(shù)據(jù),安全性更高:
executeQuery( $phql, [ "name" => "Lamborghini Espada", ] ); $phql = "SELECT * FROM Cars WHERE Cars.name = ?0"; $cars = $manager->executeQuery( $phql, [ 0 => "Lamborghini Espada", ] );插入數(shù)據(jù)(Inserting Data)
通過(guò)PHQL,可以使用我們非常熟悉的INSERT語(yǔ)句插入數(shù)據(jù):
executeQuery($phql); // 插入數(shù)據(jù),指定字段 $phql = "INSERT INTO Cars (name, brand_id, year, style) VALUES ("Lamborghini Espada", 7, 1969, "Grand Tourer")"; $manager->executeQuery($phql); // 插入數(shù)據(jù),使用占位符 $phql = "INSERT INTO Cars (name, brand_id, year, style) VALUES (:name:, :brand_id:, :year:, :style:)"; $manager->executeQuery( $phql, [ "name" => "Lamborghini Espada", "brand_id" => 7, "year" => 1969, "style" => "Grand Tourer", ] );
Phalcon不只是單純的將PHQL語(yǔ)句轉(zhuǎn)化成SQL,模型中定義的所有事件和業(yè)務(wù)規(guī)則都會(huì)執(zhí)行,就像我們手動(dòng)創(chuàng)建對(duì)象那樣。我們?yōu)槟P虲ars創(chuàng)建一條規(guī)則,車的價(jià)格不能低于$ 10,000:
price < 10000) { $this->appendMessage( new Message("A car cannot cost less than $ 10,000") ); return false; } } }
如果我們?cè)谀P虲ars中執(zhí)行下面的INSERT語(yǔ)句,操作將會(huì)失敗,因?yàn)閜rice不滿足我們制定的規(guī)則。通過(guò)檢查插入狀態(tài),我們可以打印任何內(nèi)部生成的驗(yàn)證消息:
executeQuery($phql); if ($result->success() === false) { foreach ($result->getMessages() as $message) { echo $message->getMessage(); } }更新數(shù)據(jù)(Updating Data)
更新記錄與插入記錄非常相似,更新記錄使用UPDATE命令。更新記錄時(shí),將為每條記錄執(zhí)行與更新操作相關(guān)的事件。
executeQuery($phql); // 更新多個(gè)字段 $phql = "UPDATE Cars SET price = 15000.00, type = "Sedan" WHERE id = 101"; $manager->executeQuery($phql); // 更新多條記錄 $phql = "UPDATE Cars SET price = 7000.00, type = "Sedan" WHERE brands_id > 5"; $manager->executeQuery($phql); // 使用占位符 $phql = "UPDATE Cars SET price = ?0, type = ?1 WHERE brands_id > ?2"; $manager->executeQuery( $phql, [ 0 => 7000.00, 1 => "Sedan", 2 => 5, ] );
UPDATE語(yǔ)句執(zhí)行更新分兩步進(jìn)行:
首先,如果UPDATE包含WHERE子句,將檢索符合條件的所有對(duì)象
其次,基于查詢對(duì)象更新字段并保存
這種操作方式允許事件、虛擬外鍵和驗(yàn)證參與更新過(guò)程。
101"; $result = $manager->executeQuery($phql); if ($result->success() === false) { $messages = $result->getMessages(); foreach ($messages as $message) { echo $message->getMessage(); } }
上面代碼相當(dāng)于:
101"); foreach ($cars as $car) { $car->price = 15000; if ($car->save() === false) { $messages = $car->getMessages(); return false; } } return true; }; $success = $process();刪除數(shù)據(jù)(Deleting Data)
刪除記錄時(shí),與刪除操作相關(guān)的事件將逐一執(zhí)行:
executeQuery($phql); // 刪除多條記錄 $phql = "DELETE FROM Cars WHERE id > 100"; $manager->executeQuery($phql); // 使用占位符 $phql = "DELETE FROM Cars WHERE id BETWEEN :initial: AND :final:"; $manager->executeQuery( $phql, [ "initial" => 1, "final" => 100, ] );
和UPDATE一樣,DELETE操作也分兩步執(zhí)行,要檢查刪除操作是否產(chǎn)生驗(yàn)證消息,你可以檢查返回的狀態(tài):
100"; $result = $manager->executeQuery($phql); if ($result->success() === false) { $messages = $result->getMessages(); foreach ($messages as $message) { echo $message->getMessage(); } }使用查詢構(gòu)造器創(chuàng)建查詢(Creating queries using the Query Builder)
查詢構(gòu)造器可用于創(chuàng)建PHQL查詢,無(wú)需編寫PHQL語(yǔ)句:
modelsManager->createBuilder() ->from("Robots") ->join("RobotsParts") ->orderBy("Robots.name") ->getQuery() ->execute(); // 獲取第一條記錄 $robots = $this->modelsManager->createBuilder() ->from("Robots") ->join("RobotsParts") ->orderBy("Robots.name") ->getQuery() ->getSingleResult();
同下列操作:
executeQuery($phql);
查詢構(gòu)造器更多示例:
from("Robots"); // "SELECT Robots.*, RobotsParts.* FROM Robots, RobotsParts"; $builder->from( [ "Robots", "RobotsParts", ] ); // "SELECT * FROM Robots"; $phql = $builder->columns("*") ->from("Robots"); // "SELECT id FROM Robots"; $builder->columns("id") ->from("Robots"); // "SELECT id, name FROM Robots"; $builder->columns(["id", "name"]) ->from("Robots"); // "SELECT Robots.* FROM Robots WHERE Robots.name = "Voltron""; $builder->from("Robots") ->where("Robots.name = "Voltron""); // "SELECT Robots.* FROM Robots WHERE Robots.id = 100"; $builder->from("Robots") ->where(100); // "SELECT Robots.* FROM Robots WHERE Robots.type = "virtual" AND Robots.id > 50"; $builder->from("Robots") ->where("type = "virtual"") ->andWhere("id > 50"); // "SELECT Robots.* FROM Robots WHERE Robots.type = "virtual" OR Robots.id > 50"; $builder->from("Robots") ->where("type = "virtual"") ->orWhere("id > 50"); // "SELECT Robots.* FROM Robots GROUP BY Robots.name"; $builder->from("Robots") ->groupBy("Robots.name"); // "SELECT Robots.* FROM Robots GROUP BY Robots.name, Robots.id"; $builder->from("Robots") ->groupBy(["Robots.name", "Robots.id"]); // "SELECT Robots.name SUM(Robots.price) FROM Robots GROUP BY Robots.name"; $builder->columns(["Robots.name", "SUM(Robots.price)"]) ->from("Robots") ->groupBy("Robots.name"); // "SELECT Robots.name, SUM(Robots.price) FROM Robots GROUP BY Robots.name HAVING SUM(Robots.price) > 1000"; $builder->columns(["Robots.name", "SUM(Robots.price)"]) ->from("Robots") ->groupBy("Robots.name") ->having("SUM(Robots.price) > 1000"); // "SELECT Robots.* FROM Robots JOIN RobotsParts"; $builder->from("Robots") ->join("RobotsParts"); // "SELECT Robots.* FROM Robots JOIN RobotsParts AS p"; $builder->from("Robots") ->join("RobotsParts", null, "p"); // "SELECT Robots.* FROM Robots JOIN RobotsParts ON Robots.id = RobotsParts.robots_id AS p"; $builder->from("Robots") ->join("RobotsParts", "Robots.id = RobotsParts.robots_id", "p"); // "SELECT Robots.* FROM robots JOIN RobotsParts ON Robots.id = RobotsParts.robots_id AS p JOIN Parts ON Parts.id = RobotsParts.parts_id AS t"; $builder->from("Robots") ->join("RobotsParts", "Robots.id = RobotsParts.robots_id", "p") ->join("RobotsParts", "Parts.id = RobotsParts.parts_id", "t"); // "SELECT r.* FROM Robots AS r"; $builder->addFrom("Robots", "r"); // "SELECT Robots.*, p.* FROM Robots, Parts AS p"; $builder->from("Robots") ->addFrom("Parts", "p"); // "SELECT r.*, p.* FROM Robots AS r, Parts AS p"; $builder->from(["r" => "Robots"]) ->addFrom("Parts", "p"); // "SELECT r.*, p.* FROM Robots AS r, Parts AS p"; $builder->from(["r" => "Robots", "p" => "Parts"]); // "SELECT Robots.* FROM Robots LIMIT 10"; $builder->from("Robots") ->limit(10); // "SELECT Robots.* FROM Robots LIMIT 10 OFFSET 5"; $builder->from("Robots") ->limit(10, 5); // "SELECT Robots.* FROM Robots WHERE id BETWEEN 1 AND 100"; $builder->from("Robots") ->betweenWhere("id", 1, 10); // "SELECT Robots.* FROM Robots WHERE id IN (1, 2, 3)"; $builder->from("Robots") ->inWhere("id", [1, 2, 3]); // "SELECT Robots.* FROM Robots WHERE id NOT IN (1, 2, 3)"; $builder->from("Robots") ->notInWhere("id", [1, 2, 3]); // "SELECT Robots.* FROM Robots WHERE name LIKE "%Art%""; $builder->from("Robots") ->where("name LIKE :name:", ["name" => "%" . $name . "%"]); // "SELECT r.* FROM StoreRobots WHERE r.name LIKE "%Art%""; $builder->from(["r" => "StoreRobots"]) ->where("r.name LIKE :name:", ["name" => "%" . $name . "%"]);參數(shù)綁定(Bound Parameters)
查詢構(gòu)造器中的參數(shù)綁定可以在查詢構(gòu)建時(shí)設(shè)置,也可以在查詢執(zhí)行時(shí)設(shè)置:
modelsManager->createBuilder() ->from("Robots") ->where("name = :name:", ["name" => $name]) ->andWhere("type = :type:", ["type" => $type]) ->getQuery() ->execute(); // 執(zhí)行查詢時(shí)傳遞參數(shù) $robots = $this->modelsManager->createBuilder() ->from("Robots") ->where("name = :name:") ->andWhere("type = :type:") ->getQuery() ->execute(["name" => $name, "type" => $type]);禁用字面量(Disallow literals in PHQL)
PHQL中可以禁用字面量,這意味著如果禁用開啟,則不能在PHQL語(yǔ)句中直接使用PHP字符串、數(shù)字和布爾值。如果在PHQL語(yǔ)句中嵌入外部數(shù)據(jù),可能導(dǎo)致潛在的注入攻擊:
executeQuery($phql);
如果$login的值為" OR " " = " ,將產(chǎn)生如下PHQL語(yǔ)句:
SELECT * FROM ModelsUsers WHERE login = "" OR "" = "";
無(wú)論存儲(chǔ)在數(shù)據(jù)庫(kù)中的login是何值,條件總是true。
如果字面量被禁用,在PHQL中使用PHP字面量會(huì)拋出異常,以強(qiáng)制開發(fā)者使用參數(shù)綁定。上面的查詢這樣寫更安全:
executeQuery( $phql, [ "type" => $type, ] );
可以通過(guò)以下方式禁用字面量:
false] );
無(wú)論字面量是否禁用,參數(shù)綁定都可以正常使用。禁用只是開發(fā)人員能夠在web應(yīng)用中采取的一項(xiàng)安全策略。
轉(zhuǎn)義保留字(Escaping Reserved Words)PHQL有一些保留字,如果想將保留字作為模型名或字段名使用,則需要使用轉(zhuǎn)義分隔符[和]來(lái)轉(zhuǎn)義關(guān)鍵字:
executeQuery($phql); $phql = "SELECT id, [Like] FROM Posts"; $result = $manager->executeQuery($phql);PHQL生命周期(PHQL Lifecycle)
作為高級(jí)語(yǔ)言,PHQL賦予了開發(fā)者個(gè)性化定制的能力,以滿足不同的需求。以下是PHQL語(yǔ)句的生命周期:
PHQL被解析并轉(zhuǎn)換為獨(dú)立于數(shù)據(jù)庫(kù)SQL之外的中間表示(IR)
根據(jù)模型對(duì)應(yīng)的數(shù)據(jù)庫(kù)系統(tǒng),IR被轉(zhuǎn)換為有效的SQL
PHQL語(yǔ)句被解析并保存在內(nèi)存中,再次執(zhí)行相同語(yǔ)句時(shí)速度會(huì)更快
使用原生SQL(Using Raw SQL)某些數(shù)據(jù)庫(kù)系統(tǒng)可能會(huì)提供PHQL不支持的特殊SQL擴(kuò)展,這種情況適合使用原生SQL:
0"; // 模型 $robot = new Robots(); // 執(zhí)行查詢 return new Resultset( null, $robot, $robot->getReadConnection()->query($sql) ); } }
如果原生SQL查詢?cè)趹?yīng)用中很普遍,可以在模型中添加通用方法:
getReadConnection()->query($sql), ); } }
上述findByRawSQL可以如下使用:
?", [ 10, ] );注意事項(xiàng)(Troubleshooting)
PHQL中的一些注意事項(xiàng):
類名稱區(qū)分大小寫,如果定義類時(shí)名稱和創(chuàng)建時(shí)的名稱不一致,在大小寫敏感的操作系統(tǒng)(如linux)中將導(dǎo)致不可預(yù)知行為
為保證參數(shù)綁定成功,連接數(shù)據(jù)庫(kù)時(shí)必須指定正確的字符集
指定別名的類不能用完整命名空間替換,因?yàn)檫@項(xiàng)操作發(fā)生在PHP代碼中,而非PHQL語(yǔ)句里
如果字段使用別名,應(yīng)避免別名和字段名相同,不然查詢解析器容易混淆。
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/28527.html
摘要:本文描述了框架中數(shù)據(jù)庫(kù)操作方法,主要討論框架的組件中的操作方法。屬性方法在框架中支持屬性的擴(kuò)展查詢,在上例中,可以把條件語(yǔ)句改為同時(shí)省略查詢條件結(jié)果不變。 本文描述了PHP-Phalcon框架中數(shù)據(jù)庫(kù)操作方法,主要討論P(yáng)halcon框架的Model組件中的操作方法。更詳細(xì)的Model介紹請(qǐng)參考:官方文檔 1. 連接數(shù)據(jù)庫(kù) 在Phalcon框架中,通過(guò)在DI中注入db參數(shù)來(lái)實(shí)現(xiàn)數(shù)據(jù)庫(kù)的...
摘要:初次認(rèn)識(shí)是在剛學(xué)的時(shí)候最近終于有機(jī)會(huì)用上了故此說(shuō)說(shuō)使用上的一些感受個(gè)人是很喜歡這套框架的方式使用依賴注入讓代碼組織很靈活耦合也很低但是也許是框架東西太多了遇到幾個(gè)坑上一年以上的也還沒解決不過(guò)有一定開發(fā)經(jīng)驗(yàn)的話還是可以自己修復(fù)的被這幾個(gè)坑浪費(fèi) 初次認(rèn)識(shí)phalcon是在剛學(xué)php的時(shí)候,最近終于有機(jī)會(huì)用上了.故此說(shuō)說(shuō)使用上的一些感受 個(gè)人是很喜歡phalcon這套框架的方式,使用...
摘要:幫助你開始使用的簡(jiǎn)易指南。第一種方式參考第二種方式參考使用參考簡(jiǎn)單粗暴的理解是把下的對(duì)應(yīng)成數(shù)據(jù)庫(kù)的表,類屬性對(duì)應(yīng)表字段。 幫助你開始使用 phalcon 的簡(jiǎn)易指南。 簡(jiǎn)介 Phalcon 2將于2015年4月17日發(fā)布,這個(gè)版本大約85%的代碼是基于 Zephir 語(yǔ)言重寫的。Zephir是開源的,使用類似PHP語(yǔ)法的語(yǔ)言,生成C語(yǔ)言代碼,并編譯成PHP擴(kuò)展。這提高了PHP擴(kuò)展的開發(fā)...
摘要:是什么是開源全功能棧使用擴(kuò)展編寫針對(duì)高性能優(yōu)化的框架。也是松耦合的,可以根據(jù)項(xiàng)目的需要任意使用其他對(duì)象。安裝支持版本的不支持普通方式的編譯安裝,只能通過(guò)安裝。因此安裝之前,請(qǐng)先安裝。 Phalcon 是什么? Phalcon 是開源、全功能棧、使用 C 擴(kuò)展編寫、針對(duì)高性能優(yōu)化的 PHP 5 框架。 開發(fā)者不需要學(xué)習(xí)和使用 C 語(yǔ)言的功能, 因?yàn)樗械墓δ芏家?PHP 類的方式暴露出來(lái)...
摘要:先引入類確定查詢表關(guān)聯(lián)表需要查詢的字段,這里兩個(gè)表的字段都可以當(dāng)數(shù)據(jù)很大時(shí),統(tǒng)計(jì)數(shù)據(jù)時(shí)用條件你好執(zhí)行搜索執(zhí)行模糊搜索設(shè)置條件,什么的都可以往后加注意這里的條件和原始語(yǔ)句中的語(yǔ)句剛好相反獲取查詢對(duì)象執(zhí)行并返回結(jié)果 先引入Builder類 use PhalconMvcModelQueryBuilder as QueryBuilder; public function mytestActio...
閱讀 1868·2021-09-22 15:45
閱讀 1652·2019-08-30 15:55
閱讀 1838·2019-08-29 11:16
閱讀 3312·2019-08-26 11:44
閱讀 714·2019-08-23 17:58
閱讀 2703·2019-08-23 12:25
閱讀 1637·2019-08-22 17:15
閱讀 3615·2019-08-22 16:09