I'm not a PHP developer, but having a huge amount of trouble trying to do simple things in this language. The current issue is that I am simply just trying to make a select statement, that works fine if I do it like this:
$sql = "SELECT * FROM victim WHERE steamId = 129847129847"
The rest of my logic runs:
$stmt = $this->pdo->prepare($sql);
$stmt->execute();
$user = $stmt->fetch();
if($user) {
//success
error_log('hit');
} else {
error_log('error????????????');
}
And I get the hit
in my console. Great, but that's not very useful. I want to simply just exchange the hardcoded value to something I am passing in the function.
function checkIfVictimExists($steamId)
Now I don't have ALL the code I've tried, but I've just about tried every flavor of this that I've seen on the internet and it continously hits the else no matter what I do. Again, hardcoding the steamId
, works fine, trying to inject a value does not work.
Here's my current implementation that is not working:
$sql = "SELECT * FROM victim WHERE steamId = ?";
$stmt = $this->pdo->prepare($sql);
$stmt->execute(array($steamId));
$user = $stmt->fetch();
if($user) {
//success
error_log('hit');
} else {
error_log('error????????????');
}
I know I've tried to pass it in via:
...WHERE steamId = :steamId
and
...execute(array(':steamId' => $steamId);
with no luck.
I've simply just tried to add it onto the string, as such:
...WHERE steamId = {$steamId}
AND
...WHERE steamId = ".$steamId."
AND
...WHERE steamId = ".$steamId
(thought maybe I needed an extra "?)
Literally nothing works. When I try to get error info, via $this->pdo->errorInfo()
all I get is an array like this:
[0] = 0000
[1] =
[2] =
Really at a loss for words why this would be so confusing, but obviously I am missing something that I fail to see in any of the google searches I've done. Looking for some help here now, thanks in advance.
EDIT
here is my connection logic:
...
private $pdo;
function __construct() {
$dsn = "mysql:host=".$this->dbhost.";dbname=".$this->dbname.";charset=".$this->charset;
try {
$this->pdo = new PDO($dsn, $this->username, $this->password);
$this->connectionStatus = true;
} catch(Exception $ex) {
error_log('Could not connect to DB'.$ex);
}
}