Skip to content

Instantly share code, notes, and snippets.

@tournasdim
tournasdim / TestController.php
Created June 24, 2013 19:30
A skeleton of a Laravel 4 Restfull Controller (not namespaced)
<?php
class TestController extends BaseController {
/**
* Setup the root action of this controller.
*
* @return void
*/
public function getIndex()
@tournasdim
tournasdim / composer.json
Created June 24, 2013 21:23
Laravel4 and ZF2 Composer file example
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"require": {
"laravel/framework": "4.0.*" ,
"stevemo/cpanel": "dev-develop" ,
"zendframework/zend-config": "2.*",
"zendframework/zend-http": "2.*"
},
@tournasdim
tournasdim / PDOExample.php
Created June 25, 2013 04:35
PDO with prepare statement example
<?php
mysql_connect('localhost', 'user', 'password');
mysql_select_db('myDB');
$data = mysql_real_escape_string($_POST['data']);
$query = 'SELECT column FROM table WHERE data = \'' . $data . '\'';
$result = mysql_query($query);
while($row = mysql_fetch_array($result, FETCH_NUM))
{
@tournasdim
tournasdim / PDOExample.php
Created June 25, 2013 05:05
PDO prepared statement example (with/without POST-data)
<?php
// PDO without prepared statement
$connStr = 'mysql:host=localhost;dbname=world' ;
try
{
$conn = new PDO($connStr, 'root', '');
}
catch(PDOException $pe)
{
@tournasdim
tournasdim / Mysqli.php
Created June 25, 2013 05:14
Mysqli connection example (using OOP)
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
if (mysqli_connect_errno())
{
printf("Connect failed: %s", mysqli_connect_error());
exit();
}
$query = "SELECT * FROM users WHERE user_id='$userid'";
@tournasdim
tournasdim / Mysqli.php
Created June 25, 2013 07:21
Mysqli connection example (using procedural style)
<?php
// Create connection
$con = mysqli_connect("localhost", "username", "password", "dbname");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
@tournasdim
tournasdim / Mail.php
Created June 25, 2013 07:33
Sending mail with attachment using the PHPMailer Class
<?php
/*
First downlaod the library from Google
http://code.google.com/a/apache-extras.org/p/phpmailer/
*/
require_once 'class.phpmailer.php';
$mail = new PHPMailer();
@tournasdim
tournasdim / Mail.php
Created June 25, 2013 07:38
Sending mail without attachment using the PHPMailer Class
<?php
/*
First downlaod the library from Google
http://code.google.com/a/apache-extras.org/p/phpmailer/
*/
require_once 'class.phpmailer.php';
$mail = new PHPMailer(true);
$to = "sendmailto@gmail.com";
@tournasdim
tournasdim / GetRootFacade.php
Created June 29, 2013 07:03
A quick callback to return the Root-Class of a Facade in Laravel 4
Route::get('facade' , function()
{
return get_class(App::getFacadeRoot()) ;
}) ;
@tournasdim
tournasdim / Schema.php
Created June 29, 2013 16:58
A list of Laravel's Schema commands (Laravel 4)
<?php
Schema::create('users' , function($table)
{
$table->increments('id'); Incrementing ID to the table (primary key).
$table->string('email'); VARCHAR equivalent column
$table->string('name', 100); VARCHAR equivalent with a length
$table->integer('votes'); INTEGER equivalent to the table