[4640] trunk/htdocs/system/classes/databaseconnection.php: Rework an overly-complex set of logic in DatabaseConnection::insert() for generating the query that just annoyed me.

0 views
Skip to first unread message

svn-N...@habariproject.org

unread,
Nov 27, 2010, 7:29:21 PM11/27/10
to habar...@googlegroups.com
Revision
4640
Author
chrismeller
Date
2010-11-28 00:29:20 +0000 (Sun, 28 Nov 2010)

Log Message

Rework an overly-complex set of logic in DatabaseConnection::insert() for generating the query that just annoyed me.

Modified Paths

Diff

Modified: trunk/htdocs/system/classes/databaseconnection.php (4639 => 4640)


--- trunk/htdocs/system/classes/databaseconnection.php	2010-11-28 00:28:26 UTC (rev 4639)
+++ trunk/htdocs/system/classes/databaseconnection.php	2010-11-28 00:29:20 UTC (rev 4640)
@@ -561,16 +561,11 @@
 	{
 		ksort( $fieldvalues );
 
-		$query = "INSERT INTO {$table} ( ";
-		$comma = '';
+		$fields = array_keys( $fieldvalues );
+		$values = array_values( $fieldvalues );
+		
+		$query = "INSERT INTO {$table} ( " . implode( ', ', $fields ) . ' ) VALUES ( ' . implode( ', ', array_fill( 0, count( $values ), '?' ) ) . ' )';
 
-		foreach ( $fieldvalues as $field => $value ) {
-			$query .= $comma . $field;
-			$comma = ', ';
-			$values[] = $value;
-		}
-		$query .= ' ) VALUES ( ' . trim( str_repeat( '?,', count( $fieldvalues ) ), ',' ) . ' );';
-
 		// need to pass $table on to the $o singleton object;
 		$this->current_table = $table;
 
Reply all
Reply to author
Forward
0 new messages