Results 1 to 1 of 1

Thread: How identify which insert statments fail inside a for loop ?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    How identify which insert statments fail inside a for loop ?

    Hi all. Hi all i am trying to write 100 array values in to mysql using the following code.But unfortunately from 100 array values only 97 records get inserted in to database(i checked db to verify).I wonder if there is a way to check what insert statements fail?

    However My echo $videoinfo[$i]['author'] inside prints 100 records but when i check my database i see only 97 records inserted!! Is there away to check what record number is failing to get inserted in to databases? I be happy if you help fix this problem.


    PHP Code:
    ......

    //now i need to write video detail to database
    $server   "localhost"// MySQL hostname
    $username "root"// MySQL username
    $password ""// MySQL password
    $dbname   "test"// MySQL db name

    $db mysql_connect($server$username$password) or die(mysql_error());
          
    mysql_select_db($dbname) or die(mysql_error());


    for(
    $i=0;$i<=count($videoinfo);$i++){

    [
    B]echo $videoinfo[$i]['author'];[/B]

    $query "INSERT INTO youtubevideos2(`ID`,`author`,`idyoutube`,`title`,
    `length_seconds`,`rating_avg`,`rating_count`,`description`,`view_count`,
    `upload_time`,`comment_count`,`tags`,`url`,`thumbnail_url`,`embed_id`,
    `embed_status`) VALUES ('
    $ID','" $videoinfo[$i]['author'] . "',
    '" 
    $videoinfo[$i]['id'] . "','" $videoinfo[$i]['title'] . "','" $videoinfo[$i]['length_seconds'] . "','" $videoinfo[$i]['rating_avg'] . "','" $videoinfo[$i]['rating_count'] . "','" $videoinfo[$i]['description'] . "','" $videoinfo[$i]['view_count'] . "','" $videoinfo[$i]['upload_time'] . "','" $videoinfo[$i]['comment_count'] . "','" $videoinfo[$i]['tags'] . "','" $videoinfo[$i]['url'] . "','" $videoinfo[$i]['thumbnail_url'] . "','" $videoinfo[$i]['embed_id'] . "','" $videoinfo[$i]['embed_status'] . "')";


    $fp fopen("youtubeVideos.txt""w");
    fwrite($fp$query);
    fclose($fp);      
    $result mysql_query$query );

    }


    ..... 
    Last edited by tony007; Oct 15th, 2007 at 04:47 AM.

Posting Permissions

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



Click Here to Expand Forum to Full Width