{ Snipperize } /database
Snippets about database
Compact Access DB with ADO
'Needs Microsoft Jet and Replication Objects Library 'Needs Microsoft ActiveX Data Objects Library 'Needs Microsoft Scripting Runtime
Visual Basic / access, database, ado / by ThePeppersStudio (43 days, 17.12 hours ago)
Escape single quotes in strings for SQLite3 database
This function will escape the NSString for SQLite3 database. You can use this function to escape or change any other character.
Objective-C / NSString, escape, sqlite, database / by ThePeppersStudio (50 days, 19.99 hours ago)
Database Helper Class
<?php // Example of usage // // Connecting // On this example, I'm using constants just because I was using this class within an app. define('DB_HOST','localhost'); define('DB_USER','root'); define('DB_PSWD','pswd'); define('DB_DB','posts'); $Db = new Database(); // Inserting a post in table 'posts' with 3 fields/columns: author,title,text // Note that third parameter is optional if the second is already in correct column order $Db->insert('posts',"'Shino','First post','First post text'","'author','title','text'"); // If we had a field 'id' as a primary key and first field/column we would want to get the auto_increment before iserting $new_post_id = $Db->getIncrement('posts'); $Db->insert('posts',"'".$new_post_id."','Shino','Second post','Second post text'"); // Retrieving posts list $posts = $Db->select('posts','title,text,author',"where author='Shino'"); // We could do the following too: // $Db->select('posts','',"where author='Shino'"); // Ommiting the second parameter is the same as '*' while($post = $Db->assoc($posts)) { echo '<h1>'.$post['title'].'</h1>'; echo '<h3>'.$post['author'].'</h3>'; echo '<p>'.$post['text'].'</p>'; } echo '<strong>Articles found: '.$Db->nr($posts).'</strong>'; // Updating post $Db->update('posts',"author='Dee'","id='10'"); // Number of posts updated // We set the parameter to true indicating that it is a update query's result. // We do this because if you accidentaly don't alter anything, for MySQL, it won't look like a update, and the affected_rows will be 0. echo $Db->ar(true).' posts updated'; // Deleting posts with author 'Shino' $Db->delete('posts',"author='Shino'"); // Number of posts deleted echo $Db->ar().' posts deleted'; // Number of queries executed by query() or select() on this page echo $Db->totalQueries(); ?>
PHP / database, helper / by ThePeppersStudio (233 days, 20.92 hours ago)
- 1
- Home
- New Snippet
- Languages
-

