Is there a way to convert an integer to a string in PHP?
Answers
It depends on the driver used between php and mysql.
Check which one of them is used by checking pdo_mysql section of the output of
php -i
your output should be similar to
pdo_mysql
PDO Driver for MySQL => enabled
Client API version => mysqlnd 5.0.12-dev - 20150407 - $Id: b396954eeb2d1d9ed7902b8bae237b287f21ad9e $
The native driver return integers as integers, but the other return them as strings.
So the solution is to remove the old driver and install the native one.
or to use $casts
into your model.
protected $casts = [
'status' => 'integer',
];
This is either a bug in TypeScript or a concious design decision, but you can work around it using:
var myBool: bool = true;
var myString: string = String(myBool);
alert(myString);
In JavaScript booleans override the toString
method, which is available on any Object
(pretty much everything in JavaScript inherits from Object
), so...
var myString: string = myBool.toString();
... should probably be valid.
There is also another work around for this, but I personally find it a bit nasty:
var myBool: bool = true;
var myString: string = <string><any> myBool;
alert(myString);
After analyzing your riddle, I think this is what you want:
$one = $_REQUEST["term"] . "%";
This appends the %
sql placeholder to that search term. (That's what I surmise here.)
You can use the
strval()
function to convert a number to a string.From a maintenance perspective its obvious what you are trying to do rather than some of the other more esoteric answers. Of course, it depends on your context.