randomsai Posted February 14, 2010 Share Posted February 14, 2010 I am developing a text message based application where I I would receive a text messages from mobile phones. These messages would be stored in a database, along with the source number and date. I have another database where i have the response to these messages from the mobile phones. An application would run every 5 minutes, where it would query the database for any new entries and for each new entry in the database, I would need to send a response. Can anyone help, this is the code i have thus far: <?php $a = mysql_connect("localhost", "root", ""); mysql_select_db("sms", $a); $data = mysql_query("SELECT * FROM incoming ORDER BY DATETIME DESC"); while($info = mysql_fetch_array( $data )); { $mes = $info['TEXT']; $num = $info['NUMBER']; $datt = $info['DATETIME']; $b = mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("sms", $b); $da = mysql_query("SELECT * FROM outgoing ORDER BY DATETIME DESC"); while($in = mysql_fetch_array( $da )) ; { $datee = $in['DATETIME']; if ($datt == $datee) { break; } else { if ($mes == "NEWS") { mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("info") or die(mysql_error()); $data = mysql_query("SELECT * FROM news ORDER BY DATETIME DESC") or die(mysql_error()); $info = mysql_fetch_array( $data ); $des = $info['DESCRIPTION']; echo "$des"; $con = mysql_connect("localhost", "root", ""); mysql_select_db("sms", $con); mysql_query("INSERT INTO outgoing (TEXT, NUMBER, DATETIME) VALUES ('$des' , '$num' , '$datt')"); mysql_close($con); } elseif ($mes == "WTH") { mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("info") or die(mysql_error()); $data = mysql_query("SELECT * FROM weather ORDER BY DATETIME DESC") or die(mysql_error()); $info = mysql_fetch_array( $data ); $des = $info['DESCRIPTION']; echo "$des"; $con = mysql_connect("localhost", "root", ""); mysql_select_db("sms", $con); mysql_query("INSERT INTO outgoing (TEXT, NUMBER, DATETIME) VALUES ('$des' , '$num' , '$datt')"); mysql_close($con); } else { $des = "INCORRECT FORMAT. PLEASE TRY AGAIN"; echo $des; $con = mysql_connect("localhost", "root", ""); mysql_select_db("sms", $con); mysql_query("INSERT INTO outoing (TEXT, NUMBER, DATETIME) VALUES ('$des' , '$num' , '$datt')"); mysql_close($con); } } } } ?> Link to comment https://forums.phpfreaks.com/topic/192057-having-a-persistant-connection-to-two-databases/ Share on other sites More sharing options...
trq Posted February 15, 2010 Share Posted February 15, 2010 Where exactly are you stuck? Link to comment https://forums.phpfreaks.com/topic/192057-having-a-persistant-connection-to-two-databases/#findComment-1012414 Share on other sites More sharing options...
randomsai Posted February 15, 2010 Author Share Posted February 15, 2010 well it is not exactly that i am stuck. when i get my first value and it loops back to to the while statement for the SMS database, it does not return the second value. even if suppose my second value is NEWS, it would give me INCORRECT FORMAT message. i think it happen because the connection is lost, as i connect to another database to get the value for a specific SMS message. Anyway you can help? Link to comment https://forums.phpfreaks.com/topic/192057-having-a-persistant-connection-to-two-databases/#findComment-1012780 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.