הוסטס - פורום אחסון האתרים הגדול בישראל

הוסטס - פורום אחסון האתרים הגדול בישראל (https://hosts.co.il/forums/index.php)
-   פורום תיכנות (https://hosts.co.il/forums/forumdisplay.php?f=14)
-   -   php&SQL | ייצוא כל השורות במסד ליצירה חוזרת. (https://hosts.co.il/forums/showthread.php?t=70706)

Derey22 31-12-08 16:01

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

יש דרך אחרת יעילה,מהירה יותר?

exciter 01-01-09 15:20

לעשות export ? :)

Derey22 02-01-09 16:48

ציטוט:

נכתב במקור על ידי exciter (פרסם 690101)
לעשות export ? :)

תודה אבל כבר הסתדרתי.


כל הזמנים הם GMT +2. הזמן כעת הוא 17:45.

מופעל באמצעות VBulletin גרסה 3.8.6
כל הזכויות שמורות ©
כל הזכויות שמורות לסולל יבוא ורשתות (1997) בע"מ