PHP PDO, Binding not working -
very new this. connection working fine, i'm able insert/select/delete database etc, once start trying make secure, using binding, it's doing nothing. afternoon i've been assuming it's syntax, i'm still getting used to, i've tried , gone through countless tutorials. works, until start binding. when run code below, nothing happens. after running , checking db, there's been no insertion.
here's code right now... i've stripped basics. shouldn't work? else wrong? i'm starting think it's wrong server or something.
<?php //connection working before $query = $db->prepare("insert players (name) values (:name)"); $query->bindparam(':name', 'john smith'); $query->execute(); ?>
just in case, here's connection routine....
try { $db = new pdo('mysql:host=localhost;dbname=xxx;charset=utf8', 'xx', 'xxx', array( pdo::attr_emulate_prepares => false, pdo::attr_errmode => pdo::errmode_exception )); echo "connected"; } catch(pdoexception $e) { echo $e->getmessage(); }
having no problems connection.
for bindvalue(), first parameter needs identifier value, in case ':name'. second parameter value being bound variable passed method $name, take here
$dbhandler = self::gethandler(); // prepare query: $stmthandler= $dbhandler->prepare("insert players (name) values (:name)"); // bind value: $stmthandler->bindvalue(':name', $name); // execute query: $stmthandler->execute();
php.net better job explaining here
hope helps you.
Comments
Post a Comment