\n"; - print_r($db_dest->errorInfo()); - echo "\n"; - } - $x = 0; - foreach ($result2 as $row2) { - if ($db_dest_type == "sqlite") { - $destination_column_array[$x] = $row2['name']; - } - if ($db_dest_type == "mysql") { - $destination_column_array[$x] = $row2['Field']; - } - if ($db_dest_type == "pgsql") { - - } - $x++; - } - /* - $x = 0; - foreach ($result2[0] as $key => $value) { - if ($db_dest_type == "sqlite" && $key == "name") { - $destination_column_array[$x] = $key; - } - $x++; - } - */ - $destination_column_array_count = count($destination_column_array); - } - unset($prep_statement_2, $result2); - //echo "
\n"; - //print_r($destination_column_array); - //echo "\n"; - - //get the table source data - $tmp_sql = "select * from $table_name"; - if (strlen($tmp_sql) > 0) { - $prep_statement_2 = $db->prepare(check_sql($tmp_sql)); - if ($prep_statement_2) { - $prep_statement_2->execute(); - $result2 = $prep_statement_2->fetchAll(PDO::FETCH_ASSOC); - } - else { - echo "".$text['label-error'].":\n"; - echo "
\n"; - print_r($db->errorInfo()); - echo "\n"; - } - - $x = 0; - foreach ($result2[0] as $key => $value) { - $column_array[$x] = $key; - $x++; - } - - foreach ($result2 as &$row) { - //build the sql query string - if (substr($table_name, 0, 2) == 'v_') { - $sql = "INSERT INTO $table_name ("; - $x = 1; - foreach ($destination_column_array as $column) { - if ($x < $destination_column_array_count) { - $sql .= "".$column.", "; - } - else { - $sql .= "".$column.""; - } - $x++; - } - $sql .= ") "; - $sql .= "VALUES( "; - $x = 1; - foreach ($destination_column_array as $column) { - if ($x < $destination_column_array_count) { - //if ($column == "domain_uuid") { - // $sql .= "'".$dest_domain_uuid."',"; - //} - //else { - $sql .= "'".check_str($row[$column])."', "; - //} - } - else { - //if ($column == "domain_uuid") { - // $sql .= "'".$dest_domain_uuid."'"; - //} - //else { - $sql .= "'".check_str($row[$column])."'"; - //} - } - $x++; - } - $sql .= ");\n"; - } - //add the sql into the destination database - echo $sql."
| ".$text['header-databases']." | \n"; - echo ""; - echo " \n"; - if (if_group("superadmin")) { - echo " \n"; - } - echo " | \n"; - echo "
| \n";
- echo " ".$text['description-databases'].". \n"; - echo " | \n";
- echo " |
| \n"; - echo " | ||||
| ".escape($row['database_type'])." | \n"; - echo "".escape($row['database_host'])." | \n"; - echo "".escape($row['database_name'])." | \n"; - echo "".escape($row['database_description'])." | \n"; - echo ""; - echo " ".$v_link_label_edit."\n"; - echo " | \n"; - echo "
%s', print_r($rows, true)); - $row_count = count($rows); - //printf('
%s', print_r($rows, true)); - for ($i = 0; $i < $row_count; $i++) { - array_push($fields, $rows[$i]['name']); - } - return $fields; - } else { - $query = sprintf("SELECT * FROM information_schema.columns - WHERE table_schema='%s' AND table_name='%s';" - , $db_name, $table - ); - $stmt = $db->prepare($query); - $result = $stmt->execute(); - $rows = $stmt->fetchAll(PDO::FETCH_NAMED); - $row_count = count($rows); - //printf('
%s', print_r($rows, true)); - for ($i = 0; $i < $row_count; $i++) { - array_push($fields, $rows[$i]['COLUMN_NAME']); - } - return $fields; - } - } -} - -if ($db_type == "sqlite") { - if (!function_exists('phpmd5')) { - function phpmd5($string) { - return md5($string); - } - } - - if (!function_exists('php_unix_timestamp')) { - function php_unix_timestamp($string) { - return strtotime($string); - } - } - - if (!function_exists('phpnow')) { - function phpnow() { - return date("Y-m-d H:i:s"); - } - } - - if (!function_exists('php_left')) { - function php_left($string, $num) { - return substr($string, 0, $num); - } - } - - if (!function_exists('php_right')) { - function php_right($string, $num) { - return substr($string, (strlen($string)-$num), strlen($string)); - } - } - - if (!function_exists('php_sqlite_data_type')) { - function php_sqlite_data_type($string, $field) { - - //get the string between the start and end characters - $start = '('; - $end = ')'; - $ini = stripos($string,$start); - if ($ini == 0) return ""; - $ini += strlen($start); - $len = stripos($string,$end,$ini) - $ini; - $string = substr($string,$ini,$len); - - $str_data_type = ''; - $string_array = explode(',', $string); - foreach($string_array as $lnvalue) { - $fieldlistarray = explode (" ", $value); - unset($fieldarray, $string, $field); - } - - return $str_data_type; - } - } //end function - - //database connection - try { - //$db = new PDO('sqlite2:example.db'); //sqlite 2 - //$db = new PDO('sqlite::memory:'); //sqlite 3 - $db = new PDO('sqlite:'.realpath($db_path).'/'.$db_name); //sqlite 3 - - //add additional functions to SQLite so that they are accessible inside SQL - //bool PDO::sqliteCreateFunction ( string function_name, callback callback [, int num_args] ) - $db->sqliteCreateFunction('md5', 'phpmd5', 1); - $db->sqliteCreateFunction('unix_timestamp', 'php_unix_timestamp', 1); - $db->sqliteCreateFunction('now', 'phpnow', 0); - $db->sqliteCreateFunction('sqlitedatatype', 'php_sqlite_data_type', 2); - $db->sqliteCreateFunction('strleft', 'php_left', 2); - $db->sqliteCreateFunction('strright', 'php_right', 2); - } - catch (PDOException $error) { - print "error: " . $error->getMessage() . "
".$error."
| ".escape($key)." | \n"; - $column_array[$x++] = $key; - } - echo "
|---|
| ".escape($row[$column])." | \n"; - } - } - echo "
".$error."
".$error."