Check if value exist in mysql

后端 未结 2 713
粉色の甜心
粉色の甜心 2021-01-27 14:18

I have a small script to upload data to mysql database from a csv file and I want to check the list of values that are inside of the csv file.

CSV File:

         


        
2条回答
  •  既然无缘
    2021-01-27 15:11

    As others have said, you should really use PDO. But, to answer your question, mysql_num_rows is your solution.

    $query = mysql_query("SELECT * FROM products WHERE code='$line_of_data[0]' AND alert_quantity = '$line_of_data[1]'") or die(mysql_error());
    
    if (mysql_num_rows($query))
    // Data is already in database
    else
    // Data not in database
    

提交回复
热议问题