Hi All,
Running the following in PHP on a rather large database table and getting the message that I’m running out of memory. I know I could just allocate more memory to PHP but I’m wondering if there’s a more elegant solution?
What I’m going for is to pull the data out of an MSSQL database and insert it into a MySQL database running on a different machine.
function get_Transaction_Tender() {
$sql = "
SELECT
*
FROM
Transaction_Tender
";
$db = connect_to_wp();
$q = send_query($sql, $db);
$db2 = connect_mysql();
while ($q->fetchInto($row)){
$sql2 = "INSERT INTO prism_transactions.Transaction_Tender VALUES ( '$row[0]', '$row[1]', '$row[2]', '$row[3]', '$row[4]', '$row[5]', '$row[6]', '$row[7]', '$row[8]', '$row[9]', '$row[10]', '$row[11]', '$row[12]', '$row[13]', '$row[14]', '$row[15]' )";
//print "
Inserting $row[0] $row[1] $row[2] $row[3] $row[4] $row[5] $row[6] $row[7] $row[8] $row[9] $row[10] $row[11] $row[12] $row[13] $row[14] $row[15] into local Transaction_Types";
send_query($sql2, $db2);
} // end while
disconnect($db);
disconnect($db2);
return 0;
} // end function definition for get_Transaction_Tender
Where the function connect_to_wp() is defined as:
function connect_to_wp() {
require_once('DB.php');
$db = DB::connect("odbc://XXXXXXXX:XXXXXXXXX@/Winprism");
// ...and check for errors.
if (DB::iserror($db)) {
die($db->getDebugInfo());
}
return $db;
}
The function connect_mysql() is:
function connect_mysql() {
require_once('DB.php');
$db2 = DB::connect("mysql://XXXXXX:XXXXXX@localhost/prism_transactions");
// and error check this connection
if (DB::iserror($db2)) {
die($db2->getDebugInfo());
}
return $db2;
} // end function definition for connect_mysql()
And, the function send_query($sql, $db) is defined as:
function send_query($sqlText, $db) {
// prepare the query
$sql = $db->prepare("$sqlText");
if (PEAR::isError($sql)) {
die($sql->getDebugInfo());
}
// and execute it on the database at $db
$q =& $db->execute($sql);
if (PEAR::isError($q)) {
die($q->getDebugInfo());
}
return $q;
}
Any thoughts?
Thanks in advance.
kev.