Welcome Guest, Not a member yet? Register   Sign In
convert value from routes/uri to string
#8

(04-15-2019, 06:26 PM)DELE Wrote: I know and I have tried it and failed if I use the method above. the error is only caused because the value of value is not string type. if I use a basic query I am not happy to see $value flanked by single quotes, if I use an automatic query builder consider the value of $value to be a string but the disadvantage (in my opinion) if using this method is less flexibility.

In my testing, it does not matter if $value is a string or an integer. Nor does it matter if the string is flanked with single quotes or not.
My test set up has the $key field of type int. I can set $value to a digit or a string representation of that digit and the correct record is returned.

In other words, using this code
PHP Code:
$sql "SELECT * FROM users WHERE $key = ?";
$query $this->db->query($sql, array($value)); 

I get the same results from either of these

PHP Code:
$value 307;
$value '307'

Are using some other non-string data type for the $key field?
Reply


Messages In This Thread
convert value from routes/uri to string - by DELE - 04-13-2019, 01:42 AM
RE: convert value from routes/uri to string - by dave friend - 04-16-2019, 07:02 AM



Theme © iAndrew 2016 - Forum software by © MyBB