#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    12
    Rep Power
    0
    Hi,

    I need to transfer data from one MySQL server to another one by php script. I have a simple script that takes all data from table "contact" of MySQL database "test" on remote server and transfer them to table "contact" of another MySQL database "all" on local server.

    Everything works fine even if table "contact" contains a lot of records.

    But if a field contains ' (for example O'Brian in the name field ) this record does not transfer at all.

    Could somebody help?

    Thanks in advance.

    Roman

    e-mail: roman@astelit.ru

    Here is above mentioned script named transfer.php3 :

    <?php

    Function Transfer () { global $id, $name, $email, $extension, $nick

    mysql_connect("remote host name","username","password");

    $database="test";
    @mysql_select_db($database) or die( "Unable to select database");


    $query="insert into contact values('$id','$name','$email','$extension','$nick')";

    $result=mysql_query($query);

    }

    mysql_connect(localhost,username,password);
    $database="all";

    @mysql_select_db("$database") or die( "Unable to select database");

    $table="contact";

    $query="select * from $table";

    $result=mysql_query($query);


    $num=mysql_numrows($result);

    $i=0;
    while ($i < $num):

    $name=mysql_result($result,$i,"name");
    $email=mysql_result($result,$i,"email");
    $extension=mysql_result($result,$i,"extension");
    $nick=mysql_result($result,$i,"nick");
    $id=mysql_result($result,$i,"id");

    Transfer ();

    $i++;
    endwhile;

    ?>
  2. #2
  3. No Profile Picture
    Gödelian monster
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 1999
    Location
    Central Florida, USA
    Posts
    2,307
    Rep Power
    62
    look at the "addslashes()" and "stripslashes()" functions at www.php.net

    While you're at it, you should also look at the "mysql_pconnect" function. (Opens a persistant connection--no need to open and close the connection for every INSERT)
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    12
    Rep Power
    0
    Dear Rycamor,

    Thanks. It works.

    Roman

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by rycamor:
    look at the "addslashes()" and "stripslashes()" functions at www.php.net

    While you're at it, you should also look at the "mysql_pconnect" function. (Opens a persistant connection--no need to open and close the connection for every INSERT)
    [/quote]

Similar Threads

  1. accessing mysql data from excel
    By asiva in forum Visual Basic Programming
    Replies: 1
    Last Post: December 11th, 2003, 06:49 AM
  2. accessing mysql data from excel vba
    By asiva in forum MySQL Help
    Replies: 1
    Last Post: December 11th, 2003, 01:58 AM
  3. Replies: 2
    Last Post: December 2nd, 2003, 02:52 PM
  4. multiple data directories with one MySQL server?
    By drdre69 in forum MySQL Help
    Replies: 4
    Last Post: October 29th, 2003, 07:17 PM
  5. MySQL bad for large binary data? Oracle better?
    By torbjoen in forum MySQL Help
    Replies: 5
    Last Post: April 22nd, 2002, 04:10 AM

IMN logo majestic logo threadwatch logo seochat tools logo