Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post

    can't insert more than 2503 values...

    Hey, having issues with adding more than 2503 values into a table. If I re-run the code the same values are added AGAIN so it's not the table limiting the rows.

    PHP Code:
    <?php
    include("php/connect.php");
    $data file("word.php");
    $i 0;

    foreach(
    $data as $val) {
        
    $sql "INSERT INTO dictionary (word) VALUES ('".$val."')";
        
    mysql_query($sql);
        echo 
    $i.": ".$val.
        <b>Status: "
    .(!mysql_query($sql$con) ? "<span style='color:red;'>Failed!</span>" "<span style='color:green;'>Ok!</span>")."</b><br />";
        
    $i++;
    }
    ?>

  • #2
    New Coder
    Join Date
    Apr 2012
    Posts
    23
    Thanks
    3
    Thanked 1 Time in 1 Post
    What are you looking for? Do you want it to stop at 2503?

    ALSO, you would not need i++ as the variable i does not do anything at all in this case
    Last edited by chunky; 04-16-2012 at 07:33 PM.

  • #3
    Regular Coder
    Join Date
    Apr 2004
    Posts
    298
    Thanks
    0
    Thanked 23 Times in 23 Posts
    what does this display
    PHP Code:
    <?php
    include("php/connect.php");
    $data file("word.php");
    echo 
    count($data);
    exit();

  • #4
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post
    Quote Originally Posted by chunky View Post
    What are you looking for? Do you want it to stop at 2503?

    ALSO, you would not need i++ as the variable i does not do anything at all in this case
    If I wanted it to stop I wouldn't make a thread saying that I can't inset more than 2503 values... And I added the $i so I can echo the word number... so then I know how many have added.

    Quote Originally Posted by litebearer View Post
    what does this display
    PHP Code:
    <?php
    include("php/connect.php");
    $data file("word.php");
    echo 
    count($data);
    exit();
    That produces 26878

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    So you intend to issue 27K commands to a MySQL server?
    Um, no. That's too many requests. As is you could be suffering from memory or time limitations.
    Split them up into blocks of 750 and see how it does.
    PHP Code:
    $aParts array_chunk($data750);
    $iParts count($aParts);
    $iInserted 0;
    for (
    $i 0$i $iParts; ++$i)
    {
        
    $iWords count($aParts[$i]);
        if (
    $iWords 0)
        {
            
    $sQry 'INSERT INTO dictionary (word) VALUES ';
            for (
    $j 0$j $iWords; ++$j)
            {
                if (
    $j 0)
                {
                    
    $sQry .= ', ';
                }
                
    $sQry .= '(' $aParts[$i][$j] . ')';
            }
            if (
    mysql_query($sQry$con))
            {
                
    $iInserted += mysql_affected_rows($con);
            }
        }
    }
    printf("Successfully inserted %d records"$iInserted); 
    That will limit the number of queries to 35 instead of near 27,000. Try that.

  • Users who have thanked Fou-Lu for this post:

    martynball (04-16-2012)

  • #6
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post
    "Successfully inserted 0 records"

  • #7
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,280
    Thanks
    12
    Thanked 342 Times in 338 Posts
    esp. for that (multiple inserts) I’d use Prepared Statements.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    ^
    I'd also use a bind. But I'll assume you don't have a PDO or MySQLi library to work with and that's why you are using mysql library.
    Biffed it since these are strings, not numbers. Use this for the concat in the loop:
    PHP Code:
    $sQry .= "('" $aParts[$i][$j] . "')"

  • #9
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,280
    Thanks
    12
    Thanked 342 Times in 338 Posts
    Quote Originally Posted by Fou-Lu View Post
    But I'll assume you don't have a PDO or MySQLi library to work with and that's why you are using mysql library.
    would be a good question to verify.

    (though most (new) coders don’t even know about PDO/MySQLi))
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #10
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post
    "Successfully inserted 8250 records", would a delay help?

    Edit: It's basically just a dictionary.

  • #11
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Enable your error reporting:
    PHP Code:
    ini_set('display_errors'1);
    error_reporting(E_ALL); 
    Do you run out of time?
    Consider adding an else to the mysql_query if as well to see if it dumps an error. I wouldn't suspect that this is caused by a forced max queries per minute, but it is possible.

  • #12
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post
    PHP Code:
    <?php
    ini_set
    ('display_errors'1);
    error_reporting(E_ALL); 

    include 
    "php/connect.php";
    $data file("word.php");
    $aParts array_chunk($data750); 
    $iParts count($aParts); 
    $iInserted 0
    for (
    $i 0$i $iParts; ++$i

        
    $iWords count($aParts[$i]); 
        if (
    $iWords 0
        { 
            
    $sQry 'INSERT INTO dictionary (word) VALUES '
            for (
    $j 0$j $iWords; ++$j
            { 
                if (
    $j 0
                { 
                    
    $sQry .= ', '
                } 
                
    $sQry .= "('" $aParts[$i][$j] . "')";  
            } 
            if (
    mysql_query($sQry$con)) 
            { 
                
    $iInserted += mysql_affected_rows($con); 
            } else {
                echo 
    mysql_error();    
            }
        } 

    printf("Successfully inserted %d records"$iInserted);  
    ?>
    Something to do with the query :S
    Error:
    Code:
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'd '), ('I'll '), ('I'm '), ('I've '), ('IA '), ('IBM '), ('ICC '), ('ID '), ('IE' at line 1You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Brien '), ('O'Connell '), ('O'Connor '), ('O'Dell '), ('O'Donnell '), ('O'Dwyer ' at line 1You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's '), ('aardvark '), ('aback '), ('abacus '), ('abalone '), ('abandon '), ('abas' at line 1You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 't '), ('air '), ('airborne '), ('airbrush '), ('aircraft '), ('airdrop '), ('air' at line 1You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'd '), ('anyhow '), ('anyone '), ('anyplace '), ('anything '), ('anyway '), ('any' at line 1You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's '), ('cab '), ('cabal '), ('cabana '), ('cabaret '), ('cabbage '), ('cabdriver' at line 1You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 't '), ('coulomb '), ('council '), ('councilman '), ('councilmen '), ('councilwom' at line 1You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 't '), ('die '), ('died '), ('diehard '), ('dieldrin '), ('dielectric '), ('diem ' at line 1You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'er '), ('e's '), ('e.g '), ('each '), ('eager '), ('eagle '), ('ear '), ('eardru' at line 1You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's '), ('fable '), ('fabric '), ('fabricate '), ('fabulous '), ('facade '), ('fac' at line 1You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's '), ('gab '), ('gabardine '), ('gabbing '), ('gabble '), ('gabbro '), ('gable ' at line 1You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's '), ('ha '), ('habeas '), ('haberdashery '), ('habit '), ('habitant '), ('habi' at line 1You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 't '), ('hasp '), ('hassle '), ('hast '), ('haste '), ('hasten '), ('hasty '), ('' at line 1You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 't '), ('isochronal '), ('isochronous '), ('isocline '), ('isolate '), ('isomer '' at line 1You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's '), ('ma '), ('macabre '), ('macaque '), ('macaw '), ('mace '), ('macerate '),' at line 1You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 't '), ('mighty '), ('mignon '), ('migrant '), ('migrate '), ('migratory '), ('mi' at line 1You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 't '), ('musty '), ('mutagen '), ('mutandis '), ('mutant '), ('mutate '), ('mutat' at line 1You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 't '), ('ounce '), ('our '), ('ourselves '), ('oust '), ('out '), ('outermost '),' at line 1You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's '), ('qua '), ('quack '), ('quackery '), ('quad '), ('quadrangle '), ('quadran' at line 1You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's '), ('sa '), ('sabbath '), ('sabbatical '), ('sable '), ('sabotage '), ('sabra' at line 1You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 't '), ('shank '), ('shanty '), ('shape '), ('shard '), ('share '), ('sharecrop '' at line 1You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's '), ('tab '), ('tabbing '), ('tabernacle '), ('table '), ('tableau '), ('table' at line 1You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'd '), ('they'll '), ('they're '), ('they've '), ('thiamin '), ('thick '), ('thic' at line 1You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's '), ('ubiquitous '), ('ubiquity '), ('ugh '), ('ugly '), ('ulcer '), ('ulcerat' at line 1You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 't '), ('wasp '), ('waspish '), ('wast '), ('wastage '), ('waste '), ('wastebaske' at line 1Successfully inserted 8250 records

  • #13
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,280
    Thanks
    12
    Thanked 342 Times in 338 Posts
    looks like an escaping problem ('). does your host support MySQLi or PDO?
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #14
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post
    I do not know, and I can't find anything in the control panel which would tell me, I use 1freehosting.com

    Edit: I don't think it does:
    http://www.1freehosting.com/free-web...d-hosting.html

  • #15
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,280
    Thanks
    12
    Thanked 342 Times in 338 Posts
    you can find that info in the output of the phpinfo() function.

    and I wouldn’t expect it in the control panel.

    other than that, simply try new PDO() or new MySQLi(). if those are not supported you get an error message saying something like "class PDO not found". (otherwise you get errors about not connecting/missing arguments/etc.)
    Last edited by Dormilich; 04-16-2012 at 09:00 PM.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • Users who have thanked Dormilich for this post:

    martynball (04-16-2012)


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •