Php > Database Related
Load a file into a database or something
Load a file into a database or something head = 1; /* if head is set */ $this->separator = $separator; /* define separator */ $this->dbname = $name; /* wich table do we wanna insert into */ $this->dbfile = file("$file"); /* load the file into an array */ } function SetFields($fields) { $this->dbfields = $fields; /* copy */ $this->field_num = count($this->dbfields); /* count */ $this->a_keys = array_keys($this->dbfields); /* find keys */ } function LoadIntoDB() { $rows = count($this->dbfile); /* make the sting that is identical to all querys */ $start_query = "INSERT INTO ".$this->dbname." ("; for($i = 0; $i < $this->field_num; $i++) { if($i != 0) $start_query .= ", "; $start_query .= $this->dbfields[$this->a_keys[$i]]; } $start_query .= ") VALUES ("; /* Loop through all entrys and insert them */ for($i = $this->head; $i < $rows;$i++) { $query = $start_query; $this->dbfile[$i] = addslashes($this->dbfile[$i]); $n_row = explode($this->separator, $this->dbfile[$i]); for($j = 0; $j < $this->field_num; $j++) { if($j != 0) $query .= ", "; $query .= "'".$n_row[$this->a_keys[$j]]."'"; } $query .= ")"; mysql_query($query); if(mysql_affected_rows() < 1) return 0; // on failure } return 1; // on success } } ?>
Php Codes
Algorithms
Arrays
Authentication
Calendar
Code Snippets
Programs
Content Manage
Contest Related
Cookies
Credit Cards
DBase Related
Databases
Date Time
Directories
E-Mail
Errors
File
File System
Forms
Handling
Graphics
HTML and PHP
Informix
Ingres
InterBase
LDAP
Look and Feel
Miscellaneous
MySQL
Other
PHP Classes
Searching
Navigation
Statistics
Strings
User Manage