I've seen a lot of questions on this, however I haven't found the answer specific to mine. I have a PHP where users input a ticket number, the information will get stored in one database, however I want to check a different database and table to check if that number is in the table. The input is a string, and I've tried intval($ticket) but still doesn't work.
$ticketQry = mysqli_prepare($con,"select count(*) from <database2>.mantis_bug_table where id =?");
mysqli_stmt_bind_param($ticketQry,'i',intval($Ticket));
mysqli_execute($ticketQry);
var_dump($ticketQry);
Result:
object(mysqli_stmt)#7 (10) { ["affected_rows"]=> int(-1) ["insert_id"]=> int(0) ["num_rows"]=> int(0) ["param_count"]=> int(1) ["field_count"]=> int(1) ["errno"]=> int(0) ["error"]=> string(0) "" ["error_list"]=> array(0) { } ["sqlstate"]=> string(5) "00000" ["id"]=> int(6) }
I found that affected_rows int(-1) means there is something wrong with the query, but I cannot for the life of me figure it out.
I tried adding a mysqli_select_db() statement to switch between the two databases and yes I removed from the SQL statement when I did this, but that didn't work.
Now if I go in phpmyadmin and put in the same parameter and sql statement, it works just fine. I did try binding it as a string as well.
If I run this in phpmyadmin, the result is 1. So again I know this is working from phpmyadmin, but not my PHP script.