Skip to content

Instantly share code, notes, and snippets.

@viccherubini
Created December 14, 2009 13:05
Show Gist options
  • Save viccherubini/256034 to your computer and use it in GitHub Desktop.
Save viccherubini/256034 to your computer and use it in GitHub Desktop.
<?php
require_once 'Artisan/Db.php';
require_once 'Artisan/Exception.php';
$db_config = array(
'server' => 'localhost',
'username' => 'username',
'password' => 'password',
'database' => 'dbname'
);
$db = new Artisan_Db($db_config);
try {
$db->connect();
$user_id = 5;
// SELECT query
$result_select = $db->select()
->from('users')
->where('user_id = ?', $user_id)
->query();
// SELECT query to return a single value
$email_address = $db->select()
->from('users')
->where('user_id = ?', $user_id)
->query()
->fetch('email_address');
$data = array(
'name' => 'Vic',
'age' => 25,
'email' => '[email protected]'
);
// INSERT query, returns the insert ID if successful
$user_id = $db->insert()
->into('users')
->values($data)
->query();
// UPDATE query
$db->update()
->table('users')
->set($data)
->where('user_id = ?', $user_id)
->query();
$db->disconnect();
} catch ( Artisan_Exception $e ) {
exit('An error occurred: ' . $e->getMessage());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment