Check if value exist in mysql

后端 未结 2 684
粉色の甜心
粉色の甜心 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:04

    Please check mysql exists subqueries.

    Exists and Not Exists subqueries

    0 讨论(0)
  • 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
    
    0 讨论(0)
提交回复
热议问题