0

I am using Php MDB2 data abstraction layer and trying insert data into the MySql database using prepare/bind.

<?php
require_once 'MDB2-2.5.0b5/MDB2.php';

// setup
$dsn = 'mysqli://root:@localhost/propeldb';
$options = array ('persistent' => true);
$mdb2 =& MDB2::factory($dsn, $options);


$sql = 'INSERT INTO lb_attributes (attributename, addedby) VALUES  (?, ?)';

$statement = $mdb2->prepare($sql);

// figure out the data
$attribute_name = 'resolution';
$added_by = 'Hammett';

// bind the data
$statement->bindParam('attribute_name', $attribute_name);
$statement->bindParam('added_by', $added_by);

// execute and free
$statement->execute();
$statement->free();

This does nothing. Can you suggest what wrong am I doing.

Daksh B
  • 269
  • 1
  • 8
  • 45
  • have you got display errors turned on? Is there anything in your logs? – Liam Sorsby Nov 27 '15 at 19:56
  • @LiamSorsby, blank page .... no errors shown. Yes the error display is on. – Daksh B Nov 27 '15 at 19:57
  • you have attribute_name as the first parameter should this not be s for string – Liam Sorsby Nov 27 '15 at 20:00
  • @LiamSorsby, okay, am sorry. The error display was off. I just turned it on. Here is the error "Strict Standards: Only variables should be assigned by reference" – Daksh B Nov 27 '15 at 20:00
  • See my comment above. That should fix it. – Liam Sorsby Nov 27 '15 at 20:02
  • @LiamSorsby, you suggesting $statement->bindParam(s, $attribute_name); ? – Daksh B Nov 27 '15 at 20:03
  • Yes but you will need to put quotation marks around the s. See example 1 and 2 http://php.net/manual/en/mysqli-stmt.bind-param.php – Liam Sorsby Nov 27 '15 at 20:05
  • @LiamSorsby, not helping. I tried both $statement->bindParam('s', $attribute_name); and $statement->bindParam('ss', $attribute_name, $added_by);, nothing works. – Daksh B Nov 27 '15 at 20:10
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/96382/discussion-between-liam-sorsby-and-daksh-b). – Liam Sorsby Nov 27 '15 at 20:11
  • Ahhhh, remove the ampersand here: $mdb2 =& MDB2::factory($dsn, $options); – Liam Sorsby Nov 27 '15 at 20:12
  • @LiamSorsby, did that and have a new error " Fatal error: Cannot redeclare class MDB2_Error in C:\xampp\php\pear\MDB2.php on line 977" – Daksh B Nov 27 '15 at 20:16
  • What database are you trying to connect to? I've just looked at the Pear library for the function and it doesn't look like this will work with PHP5 as =& will pass it as a reference which in PHP5 it does automatically. You can have a look here: http://pear.php.net/manual/en/package.database.mdb2.intro-connect.php – Liam Sorsby Nov 27 '15 at 20:18
  • @LiamSorsby, trying to connect the MySQL database. – Daksh B Nov 27 '15 at 20:20
  • Why not use the inbuilt mysqli function or PDO function? – Liam Sorsby Nov 27 '15 at 20:22
  • @LiamSorsby, I have untill sunday. If am unable to, ill have to leave DAL and go back to MySqli or PDO. – Daksh B Nov 27 '15 at 20:24

0 Answers0