我了解类的用处,但不知道创建具有准备好的语句的类的正确方法是什么。我已经开始创建一个类,我想要一个名为 isOnline 的方法,如果 url 在线则返回。
// This is the code I'm trying to make a class.
global $db;
$stmt = $db->prepare("SELECT url FROM urls WHERE rel=? ORDER BY url");
$stmt->bind_param("i", $_SESSION['admin_id']);
$stmt->execute();
$result = $stmt->get_result();
?>
<?php
while($row = $result->fetch_array())
{
$url = $row['url'];
$site = strtolower($url);
// check if is online
$curl = curl_init();
curl_setopt_array( $curl, array(
CURLOPT_HEADER => true,
CURLOPT_NOBODY => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_URL => 'https://'.$site ) );
$headers = explode( "\n", curl_exec( $curl ) );
$statushttp = $headers[0];
if(!$statushttp == 0){
}else{
$curl = curl_init();
curl_setopt_array( $curl, array(
CURLOPT_HEADER => true,
CURLOPT_NOBODY => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_URL => 'http://'.$site ) );
$headers = explode( "\n", curl_exec( $curl ) );
$statushttp = $headers[0];
}
echo "$url with $statushttp <br>";
// email person here.
}
$stmt->free_result();