Last active
September 6, 2017 20:27
-
-
Save ozh/21602d4dbc113c6f0320161489683c25 to your computer and use it in GitHub Desktop.
Propel example with YOURLS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* For the record: I played with Propel2 ORM and checked how I could use it with YOURLS. | |
* | |
* Setting up isn't complicated: | |
* - install Propel with composer | |
* - `vendor/bin/propel init` and answer quetions to generate the schema.xml, config file and mapped classes, | |
* based on an existing DB | |
* | |
* Using isn't very complicated, but there are quite many functions to tame. | |
* I think it would tie core YOURLS functions too deeply with one ORM and its many functions, | |
* as opposed to simple PDO bind + fetch. Much much more rework in the future if for some reason we want to move from | |
* this ORM to another, or leave ORM | |
* | |
* Example with options: | |
*/ | |
require 'vendor/autoload.php'; | |
require 'generated-conf/config.php'; | |
// Add one option | |
$option = new \YOURLS\YOURLS\YourlsOptions; | |
$option->setOptionName('omg'); | |
$option->setOptionValue('yes'); | |
$option->save(); | |
// Get one option value | |
$option = new \YOURLS\YOURLS\YourlsOptionsQuery(); | |
var_dump($option->findOneByOptionName('omg')->getOptionValue()); // string 'yes' (length=3) | |
// Delete option | |
\YOURLS\YOURLS\YourlsOptionsQuery::create() | |
->filterByOptionName('omg') | |
->delete(); | |
// (Didn't check the number of SQL queries actually sent) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment