View Single Post
ישן 31-12-08, 16:01   # 1
Derey22
הוסטסניון
 
Derey22's Avatar
 
מיני פרופיל
תאריך הצטרפות: Oct 2005
מיקום: באר שבע
גיל: 30
הודעות: 2,128
שלח הודעה באמצעות ICO אל Derey22 שלח הודעה באמצעות MSN אל Derey22

Derey22 לא מחובר  

php&SQL | ייצוא כל השורות במסד ליצירה חוזרת.

בניתי סקריפט שמוציא את כל השורות שבמסד X,ומעביר אותם לשאילתת insert.
לדוגמה מסד נתונים X:
PHP קוד:
Table One
+-------------------------------------------+
|
id     |user    |password    |
+-------------------------------------------+
|
42    |mico    |132        |
+-------------------------------------------+
|
13    |nisan    |468        |
+-------------------------------------------+
|
42    |mico    |153        |
+-------------------------------------------+

Table Tow
+-------------------------------------------+
|
id     |site    |age        |
+-------------------------------------------+
|
42    |a.com    |12        |
+-------------------------------------------+
|
13    |b.com    |17        |
+-------------------------------------------+
|
42    |c.com    |89        |
+-------------------------------------------+ 
עובר ל:
PHP קוד:
INSERT INTO `One`  VALUES
(42'mico''132'''),
(
13'nisan''436'''),
(
42'mico''153''');

INSERT INTO `TowVALUES
(42'a.com''12'''),
(
13'b.com''17'''),
(
42'c.com''89'''); 
עכשיו הקוד פועל דיי לאט.

הקוד שלי:
PHP קוד:
        $result_list=mysql_query("show tables from `mysql`");
        
$insert="";
        while (
$row_list mysql_fetch_row($result_list)) {

            
$list_table=$row_list[0];
            
            
$results2 mysql_query('SELECT * FROM mysql.'.$list_table);
            
$num_max=mysql_num_fields($results2);
            
            while (
$row2 = @mysql_fetch_array($results2,MYSQL_NUM)) {

                
$insert .= "\nINSERT INTO `$results2`  VALUES (";
                for (
$x=0;$x<$num_max;$x++)
                {
                    
$insert .=$row2[$x].",";
                }
                
                
$insert=substr_replace($insert,"",-1,1);
                
$insert .= ")\n";
                
$dbtxt .= $insert;

            }
            }
            
$dbtxt $insert
יש דרך אחרת יעילה,מהירה יותר?
  Reply With Quote