0
votes

Greetins, I have some trouble with PDO functions.

MY CODE:

while (($data = fgetcsv($handle, 1000, ",", "'")) !== FALSE) {
        if($i > 0) {
            $data = str_replace('"', '', $data); 
            $myDate =  date("Y/m/d",strtotime(str_replace('-','-',$data[0])));
            $data = str_replace(' ', '', $data);
            $lastname = $data[1];
            $firstname = $data[2];
            $showdata = $db->prepare("SELECT userID FROM users WHERE firstname LIKE '%$firstname%' AND lastname LIKE '%$lastname%'");
            $showdata->execute();
            $rowas= $showdata->fetch(PDO::FETCH_ASSOC);
            $userioID = $rowas['userID'];

            $removals=$db->prepare("DELETE FROM late WHERE userID = '$userioID' AND dateandtime= '$myDate' ;");
            $removals->execute();


            $import->bindParam(1, $myDate, PDO::PARAM_STR);                      
            $import->bindParam(2, $data[4], PDO::PARAM_STR);
            $import->bindParam(3, $rowas['userID'], PDO::PARAM_STR);                
            $import->execute();
        }
        $i++;
    }

Without removals part everything is working just fine. With removals - I get error: SQLSTATE[22018]: Invalid character value for cast specification: -3030 [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression. (SQLExecute[-3030] at ext\pdo_odbc\odbc_stmt.c:254)

Any help would be appreciated.

1
Seems that something is wrong with userID part in removal... Anyone can advise? - JustinasT
Are you dealing with string values that contain Unicode characters other than those with plain ASCII equivalents? - Gord Thompson
userID values are simple numbers. - JustinasT
Obviously something is wrong with userID syntax in removals, but cant find what exactly. - JustinasT

1 Answers

0
votes

You are comparing a string to an integer. This cannot work.

userID = '$userioID'

If the "userID" is an int you cannot compare it to string like '1'. Something like this may work:

userID = $userioID

I would also consider using bindParam method in all your SQL queries.