Skip to content

Instantly share code, notes, and snippets.

@viccherubini
Created December 14, 2009 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viccherubini/256027 to your computer and use it in GitHub Desktop.
Save viccherubini/256027 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();
$some_id = 10;
$sql = "SELECT * FROM `some_table` st WHERE st.id = '" . $some_id . "'";
$db_result = $db->query($sql);
if ( $db_result->numRows() == 0 ) {
echo 'No rows returned!';
} else {
while ( $row = $db_result->fetch() ) {
// $row is a key/value array of each row matched
}
}
$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