我有一个名为functions.php的文件,其中包含许多函数,现在我要做的是存储这些函数在数据库中返回的内容。我目前正在做的是我在每个功能中启动数据库连接,并在每个连接中关闭它。它做了什么,它将数据存储在数据库中,但它也增加了我的数据库中的行。函数返回的每个值都存储在不同的行中。我希望他们在同一排。我该怎么办? 到目前为止,这是我的代码,
function h3() {
$con=mysqli_connect("localhost","root","","fyp");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$url=$_POST["urlo"];
$counter = 0;
include_once('simple_html_dom.php');
$html = file_get_html($url);
foreach($html->find('h3') as $element){
$counter++;
}
echo $counter;
mysqli_query($con,"INSERT INTO results(h3) VALUES ('$counter')");
mysqli_close($con);
}
function paragraph() {
$con=mysqli_connect("localhost","root","","fyp");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$url=$_POST["urlo"];
$counter = 0;
include_once('simple_html_dom.php');
$html = file_get_html($url);
foreach($html->find('p') as $element){
$counter++;
}
echo $counter;
mysqli_query($con,"INSERT INTO results(p) VALUES ('$counter')");
mysqli_close($con);
}