connect_error) { die("Connection failed: " . $conn->connect_error); } $urls = $data['urls']; $existingUrls = array(); $nonExistingUrls = array(); foreach ($urls as $url) { $sql = "SELECT * FROM your_table WHERE url = '$url'"; $result = $conn->query($sql); if ($result->num_rows > 0) { $existingUrls[] = $url; } else { $nonExistingUrls[] = $url; } } echo "Existing URLs:\n"; print_r($existingUrls); echo "Non-existing URLs:\n"; print_r($nonExistingUrls); $conn->close(); ?>

Replace 'your_username', 'your_password', 'your_database', 'your_table' with your actual MySQL credentials and table name.

This code will connect to your MySQL database and query the URLs from the JSON against the 'url' column in the specified table. It will then separate the URLs into two arrays - 'existingUrls' for the URLs found in the database and 'nonExistingUrls' for the URLs not found in the database. Finally, it will print the results using print_r

php现有一个json里面包含多个url键对向mysql查询这些键对并print_t查询到的结果和在mysql数据库中不存在的结果

原文地址: https://www.cveoy.top/t/topic/imBZ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录