This topic is locked
[SOLVED]

 Slow Insert performance

3/30/2011 3:12:47 PM
PHPRunner General questions
C
choanhemnhe author

Hi Members,

I want to copy 15 thousand records from one table to another in the same Database. If I create a button within PHPRunner to do this job, it takes around 3.5 minutes. If I create separate script to do this job, it takes about 30 seconds.
In PHPRunner I did as follow:

  1. Create a custom button
  2. Insert the following script into "Server" tab

    $results = CustomQuery("SELECT LName FROM Member WHERE ID<=15000");

    while($data = db_fetch_array($results)){

    CustomQuery("INSERT INTO MBackup (LName)

    VALUES ('$data[LName]')");

    My own script as follow:
    $sql = "SELECT Lname FROM Memeber WHERE ID<=15000";

    $results = mssql_query ( $sql, $conn );

    while ( $data = mssql_fetch_array ( $results ) )

    {

    mssql_query("INSERT INTO MBackup (LName)

    VALUES ('$data[LName]')");

    }


    anyone knows why PHPRunner button goes slow or anyway to improve it?
    Many thanks

    <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=16749&image=1&table=forumtopics' class='bbc_emoticon' alt=':wacko:' />

Sergey Kornilov admin 3/31/2011

You need to re-write your query so all records are inserted in one batch.
You can use INSERT INTO ... SELECT FROM ... syntax for this job:

http://dev.mysql.com/doc/refman/5.5/en/insert-select.html

C
choanhemnhe author 3/31/2011

hello,

this really helpful.

thank Admin