the following code works to grab a return value from a php run_instance script. However, the value returned ($instanceIds) is in an array format. I need to insert these values, along with the userName and serverName into an sql database in separate rows for each value that is contained within the $instanceIds array. However, where I am getting confused is that I don't know how to insert the $instanceIds into the database in a way so that the userName and serverName are inserted over and over again until the end of the array. Any help is greatly appreciated
<?php
session_start();
$name=mysql_real_escape_string($_SESSION['username']);
include 'mysql_connect.php';
// Select the database to use
mysql_select_db("database",$con);
// Describe the now-running instance to get the public URL
$result = $ec2Client->describeInstances(array(
'InstanceIds' => $instanceIds,
));
$server_record = mysql_query("INSERT INTO server_tbl (userName, serverName, serverId, isRunning) VALUES ('$name', 'runtest', '$instanceIds', 'X'");
print_r($instanceIds);
?>
mysql_real_escape_string()
is deprecated and you shouldn't use it. Switch to prepared statements.