I am implementing a script in php for a Wordpress blog. The script should be executed every five minutes. The script opens a mysql connection and I want to close it when I am finished. Can you check if it works?
$db = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
mysql_select_db("XY", $db);
//set data into $data
foreach ($data => $info) {
//do stuff inserts
}
mysql_close();
Is the approach right? I am closing the connection used in this script or I am closing also other connections?
%sto properly escape your data. DO NOT use the obsoletemysql_queryfamily of functions. Those were removed in PHP 7 because they're exceptionally dangerous and fundamentally broken.mysql_query("INSERT INTO table1 (column1) VALUES (\"$column1\");");