Hi there i'm playing with stmt for the first time (looking at converting my code over after previously using standard mysqli functions through an extension class.
However I can't seem to get it working. I'm using PHP 5.2.11 and mysql 4.1.22.
I've got a table structure like so:
CREATE TABLE IF NOT EXISTS `tags` ( `tag_id` smallint(3) unsigned NOT NULL auto_increment, `title` varchar(32) NOT NULL default '', PRIMARY KEY (`tag_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=9 ;
and here's my code, i've been using http://devzone.zend.com/article/686 and php.net as references.
$mysqli = new mysqli('***','***','***','***'); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } $stmt = $mysqli->prepare("INSERT INTO tags (title) VALUES (?)"); $stmt->bind_param('s', $title); $title = 'test 123'; $stmt->execute(); $stmt->close(); $mysqli->close();
It seems simple enough and i'd hope that it would insert "test 123" into title column with the tag_id auto incrementing. But instead title is blank (tag_id does incremenet as one would assume).
Anyone have any ideas where i'm going wrong?
=================================================
As atli pointed out and tested, it works on MYSQL version of 5 and above. So it's probably a problem with using an old version of sql although the php.net documentation says that mysqli "allows you to access the functionality provided by MySQL 4.1 and above".
If anyone can suggest another reason why it may not be working or how to get it working in my environment that would great. If not I suppose i'll keep with my own extension of the mysqli class to prepare and clean queries.