My code is Parsing HTML tags using regex and store all the links as an array inside the data base
I have a problem in my code i don't know how to fix it to save the links inside MySQL
i see this error message Error: SQLSTATE[HY093]: Invalid parameter number: Columns/Parameters are 1-based
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$domain = "https://google.com";
$input = @file_get_contents($domain) or die("Could not access file: $domain");
$regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>";
if(preg_match_all("/$regexp/siU", $input, $matches, PREG_SET_ORDER)) {
foreach($matches as $match) {
$url=$match[2];
// $match[2] = link address
// $match[3] = link text
}
}
$rows = array($domain, $url);
$stmt = $conn->prepare("INSERT INTO linkss(id, domain, url)
VALUES (NULL, :domain, :url)");
foreach($rows as $key => $value){
$stmt->bindParam($key, $value);
}
$stmt -> execute();
echo "New records created successfully";
}
catch(PDOException $e){
echo "Error: " . $e->getMessage();
}
$conn = null;