Skip to content

Instantly share code, notes, and snippets.

@AngeloR
AngeloR / gist:948632
Created April 29, 2011 17:08
Lemondoo - get_todo
<?php
function get_todo($id) {
if(is_numeric($id) && !empty($id)) {
$sql = 'select * from todo where todo_id = '.$id;
return json(db($sql));
}
}
?>
@AngeloR
AngeloR / add_todo.php
Created April 29, 2011 17:04
Lemondoo - add_todo()
<?php
function add_todo() {
$todo_title = mysql_real_escape_string($_POST['todo_title']);
$todo_text = (empty($_POST['todo_text']))?$todo_title:mysql_real_escape_string($_POST['todo_text']);
if(!empty($todo_title)) {
$sql = 'insert into todo (todo_title,todo_text) values ("'.$todo_title.'","'.$todo_text.'")';
if(db($sql)) {
return json(db('select todo_id from todo order by todo_id desc limit 1'));
}
@AngeloR
AngeloR / get_todo_list.php
Created April 29, 2011 16:49
Lemondoo - get_todo_list
<?php
function get_todo_list() {
$sql = 'select todo_id, todo_title from todo where completed != 1';
return json(db($sql));
}
?>
@AngeloR
AngeloR / lemondoo.sql
Created April 29, 2011 16:36
SQL for lemondoo
CREATE DATABASE `lemondoo` DEFAULT CHARSET utf8;
USE `lemondoo`;
CREATE TABLE `todo` (
`todo_id` int(11) not null auto_increment,
`todo_title` varchar(100),
`todo_text` text,
`completed` tinyint(4) default '0',
PRIMARY KEY (`todo_id`)
@AngeloR
AngeloR / modify_opc.php
Created April 20, 2011 17:00
Modify a row using OPCDataGrid
<?php
$dg->modify('username', function($value,$row) {
return 'modified - '.$row['user_id'].'|'.$value;
});
?>
@AngeloR
AngeloR / example_opcdatagrid.php
Created April 20, 2011 16:59
Example of OPCDataGrid usage
<?php
$res = db('select product_id,name,short_description from products order by name asc');
$dg = new OPCDataGrid($res);
$dg->fields(array(
'name' => 'Product Name',
'short_description' => 'Description'
));
@AngeloR
AngeloR / datasource.php
Created April 19, 2011 20:48
Sample datasource for OPCDataGrid implementation
<?php
$data = array(
array(
'user_id' => 1,
'username' => 'skywalkl',
'email' => '[email protected]'
),
array(
'user_id' => 2,
'username' => 'solohan',
@AngeloR
AngeloR / dump mysql
Created April 18, 2011 20:11
dump mysql database
mysqldump --user=username --password=1234 --databases your_database --opt --quote-names --allow-keywords --complete-insert > your_database.sql.bz2
@AngeloR
AngeloR / lemon_mysql.php
Created April 14, 2011 15:20
Simple mysql wrapper for lemonade-php
<?php
/**
* A quick little function to interact with a MySQL database.
*
* When working with Limonade-php a full-fledged MySQL wrapper seems like
* overkill. This method instead accepts any mysql statement and if it works
* returns either the result or the number of rows affected. If neither worked,
* then it returns false
*
* @param string $sql the sql statement you want to execute
@AngeloR
AngeloR / Step_4.php
Created April 12, 2011 04:54
Lemondoo, a limonade-php tutorial
<?php
function configure() {
$c = mysql_connect('localhost','root','');
$s = mysql_select_db('todo',$c);
}
?>