mp04 Posted December 30, 2008 Share Posted December 30, 2008 I've got some code going but I'm stuck. For some reason the query on line 41 is only producing one user when there are several in the database. The weird thing is I can take that same query and put in a hard coded timestamp and run it through phpmyadmin and it produces the desired result, several users are returned. I think overall I am overlooking something fundamental because even if it's one user returned it shouldn't be returning what it is (as you'll see below). If you pay attention to my debugging stuff (just some echos and print_r's) you'll see what I am expecting to return however, when this one record comes back the for each loop on line 50 splits the single array into each key value pair being it's own array. Which is not the desired result. # # <?php # # # $dbArray = array( # array('id' => 0, # 'host' => 'localhost', # 'user' => 'root', # 'pass' => '', # 'db' => 'forum1', # 'users_table' => '1_users' # ), # array('id' => 1, # 'host' => 'localhost', # 'user' => 'root', # 'pass' => '', # 'db' => 'forum2', # 'users_table' => '2_users' # ) # ); # // to keep track of which array index were on # $i = 0; # # // Loop through our array of databases # foreach($dbArray as $item) { # # // Set up the database connection # $dbConn1 = new mysqli($item['host'], $item['user'], $item['pass'], $item['db']); # # if($dbConn1->connect_error) { # // TODO: handle this error gracefully # // by logging it to a file and # // moving on to the next db. # // This continue is temporary. # continue; # }else{ # // Get the last users signup timestamp # $timestamp = file_get_contents('timestamp.txt'); # //echo $timestamp; # //echo $item['users_table']; # // grab all the new users since last run # $result = $dbConn1->query("SELECT * FROM `$item[users_table]` WHERE `user_regdate` > '$timestamp'"); # if($fetch = $result->fetch_assoc()) { # # # echo '<pre>'; # print_r($fetch); # echo '</pre>'; # # // We've got them lets send them to every other db # foreach($fetch as $users) { # echo '<pre>'; # print_r($users); # echo '</pre>'; # // Loop over every database but the one who's # // index were on and insert the user info. # foreach($dbArray as $db) { # // check to make sure this is the current db # // from our parent loop. # if($db['id'] = $i) { # continue; # }else{ # // create a new database connection # $dbConn2 = new mysqli($db['host'], $db['user'], $db['pass'], $db['db']); # if($dbConn2->connect_error) { # // TODO: handle this error gracefully # // by logging it to a file and # // moving on to the next db. # // This continue is temporary. # continue; # }else{ # if($dbConn2->query("INSERT INTO $db[users_table] # (`user_type`, # `group_id`, # `user_permissions`, # `user_perm_from`, # `user_ip`, # `user_regdate`, # `username`, # `username_clean`, # `user_password`, # `user_passchg`, # `user_pass_convert`, # `user_email`, # `user_email_hash`, # `user_birthday`, # `user_inactive_reason`, # `user_inactive_time`, # `user_lang`, # `user_timezone`, # `user_dst`, # `user_dateformat`, # `user_message_rules`, # `user_emailtime`, # `user_topic_show_days`, # `user_topic_sortby_type`, # `user_topic_sortby_dir`, # `user_post_show_days`, # `user_post_sortby_type`, # `user_post_sortby_dir`, # `user_notify`, # `user_notify_pm`, # `user_notify_type`, # `user_allow_pm`, # `user_allow_viewonline`, # `user_allow_viewemail`, # `user_allow_massemail`, # `user_options`, # `user_from`, # `user_icq`, # `user_aim`, # `user_yim`, # `user_msnm`, # `user_jabber`, # `user_website`, # `user_occ`, # `user_interests`, # `user_actkey`, # `user_newpasswd`, # `user_form_salt` # ) # VALUES ('$users[user_type]', # '$users[group_id]', # '$users[user_permissions]', # '$users[user_perm_from]', # '$users[user_ip]', # '$users[user_regdate]', # '$users[username]', # '$users[username_clean]', # '$users[user_password], # '$users[user_passchg]', # '$users[user_pass_convert]', # '$users[user_email]', # '$users[user_email_hash]', # '$users[user_birthday]', # '$users[user_inactive_reason]', # '$users[user_inactive_time]', # '$users[user_lang]', # '$users[user_timezone]', # '$users[user_dst]', # '$users[user_dateformat]', # '$users[user_message_rules]', # '$users[user_emailtime]', # '$users[user_topic_show_days]', # '$users[user_topic_sortby_type]', # '$users[user_topic_sortby_dir]', # '$users[user_post_show_days]', # '$users[user_post_sortby_type]', # '$users[user_post_sortby_dir]', # '$users[user_notify]', # '$users[user_notify_pm]', # '$users[user_notify_type]', # '$users[user_allow_pm]', # '$users[user_allow_viewonline]', # '$users[user_allow_viewemail]', # '$users[user_allow_massemail]', # '$users[user_options]', # '$users[user_from]', # '$users[user_icq]', # '$users[user_aim]', # '$users[user_yim]', # '$users[user_msnm]', # '$users[user_jabber]', # '$users[user_website]', # '$users[user_occ]', # '$users[user_interests]', # '$users[user_actkey]', # '$users[user_newpasswd]', # '$users[user_form_salt]')")) # { # // The insert was succesful update the timestamp file # // with the last users reg date. # file_put_contents('timestamp.txt', $users['users_regdate']); # continue; # }else{ # // TODO: handle this error gracefully # // by logging it to a file and # // moving on to the next db. # // This continue is temporary. # continue; # } # } # } # } # } # }else{ # echo 'error'; # continue; # } # } # $i++; # $dbConn1->close(); # } # # ?> # # Array # ( # [user_id] => 1 # [user_type] => 2 # [group_id] => 1 # [user_permissions] => # [user_perm_from] => 0 # [user_ip] => # [user_regdate] => 1230523953 # [username] => Anonymous # [username_clean] => anonymous # [user_password] => # [user_passchg] => 0 # [user_pass_convert] => 0 # [user_email] => # [user_email_hash] => 0 # [user_birthday] => # [user_lastvisit] => 0 # [user_lastmark] => 0 # [user_lastpost_time] => 0 # [user_lastpage] => # [user_last_confirm_key] => # [user_last_search] => 0 # [user_warnings] => 0 # [user_last_warning] => 0 # [user_login_attempts] => 0 # [user_inactive_reason] => 0 # [user_inactive_time] => 0 # [user_posts] => 0 # [user_lang] => en # [user_timezone] => 0.00 # [user_dst] => 0 # [user_dateformat] => d M Y H:i # [user_style] => 1 # [user_rank] => 0 # [user_colour] => # [user_new_privmsg] => 0 # [user_unread_privmsg] => 0 # [user_last_privmsg] => 0 # [user_message_rules] => 0 # [user_full_folder] => -3 # [user_emailtime] => 0 # [user_topic_show_days] => 0 # [user_topic_sortby_type] => t # [user_topic_sortby_dir] => d # [user_post_show_days] => 0 # [user_post_sortby_type] => t # [user_post_sortby_dir] => a # [user_notify] => 0 # [user_notify_pm] => 1 # [user_notify_type] => 0 # [user_allow_pm] => 1 # [user_allow_viewonline] => 1 # [user_allow_viewemail] => 1 # [user_allow_massemail] => 0 # [user_options] => 895 # [user_avatar] => # [user_avatar_type] => 0 # [user_avatar_width] => 0 # [user_avatar_height] => 0 # [user_sig] => # [user_sig_bbcode_uid] => # [user_sig_bbcode_bitfield] => # [user_from] => # [user_icq] => # [user_aim] => # [user_yim] => # [user_msnm] => # [user_jabber] => # [user_website] => # [user_occ] => # [user_interests] => # [user_actkey] => # [user_newpasswd] => # [user_form_salt] => c43cef2ad73bbec7 # ) # # 1 # # 2 # # 1 # # 0 # # 1230523953 # # Anonymous # # anonymous # # 0 # # 0 # # 0 # # 0 # # 0 # # 0 # # 0 # # 0 # # 0 # # 0 # # 0 # # 0 # # 0 # # en # # 0.00 # # 0 # # d M Y H:i # # 1 # # 0 # # 0 # # 0 # # 0 # # 0 # # -3 # # 0 # # 0 # # t # # d # # 0 # # t # # a # # 0 # # 1 # # 0 # # 1 # # 1 # # 1 # # 0 # # 895 # # 0 # # 0 # # 0 # # c43cef2ad73bbec7 # # error So hopefully someone passing by this thread could help me out. Whoever does, just keep in mind that the code above isn't finished and if you use it on your system I'm not responsible for any loss or damage it may cause. Quote Link to comment https://forums.phpfreaks.com/topic/138885-cannot-copy-more-then-one-with-php-timestamp/ Share on other sites More sharing options...
premiso Posted December 30, 2008 Share Posted December 30, 2008 http://us2.php.net/manual/en/mysqli-result.fetch-assoc.php You need to put it in a while loop like seen at the example above to get all the rows back properly. Quote Link to comment https://forums.phpfreaks.com/topic/138885-cannot-copy-more-then-one-with-php-timestamp/#findComment-726234 Share on other sites More sharing options...
mp04 Posted December 30, 2008 Author Share Posted December 30, 2008 Thanks. I will test it out, and get back to you. Thanks for your help! Quote Link to comment https://forums.phpfreaks.com/topic/138885-cannot-copy-more-then-one-with-php-timestamp/#findComment-726253 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.