[INFO] vPHP and binded values

Ivan Smahin ivan_smahin at paradigmasoft.com
Tue Nov 30 23:39:59 CST 2010


Hello Danny,

  Just for info...

  PHP
  ------

  There are new features in the current build:

  Currently you may pass as binded values following things:
        • NULLs
        • Bools, longs, doubles, strings
        • Arrays (we will concat all elements in a single string value)
        • IS_OBJECT which must be php_vbinary_value - no idea how to get such object in PHP
        
  Examples:

  // Load binary content and write it as a Picture and as a BLOB to the db.
  $filename = "WallPaperHD - 146.jpg";
  $handle = fopen($filename, "rb");
  $filecontents = fread($handle, filesize($filename));
  fclose($handle);

  // Array of lines. - can be used to make a binded value representing text of file
  // But better do the same as above (for binary file)
  $fileAsArray = file('test.txt');


  // Creating array with binding values
  $binds_array = array( 25, 2020, "Smith Jones Binded", $filecontents, $fileAsArray , NULL);

  valentina_query("INSERT INTO ".test_table." (age, salary, name, test1, test2, v) VALUES(:1, :2, :3, :4, :5, :6)", $binds_array) or
        die( "insert statement crashed!");


  PDO
  ------

  How to pass nulls as binded value.

  Example:

  $name = "Frost";
  $sql = "INSERT INTO Person (Name, Age ) VALUES (?, ?)";
  $sth = $dbh->prepare($sql);
  $sth->bindValue(1 , $name, PDO::PARAM_STR);
  $sth->bindValue(2 , NULL,  PDO::PARAM_NULL);
  $sth->execute();

  Actually it concats the string to be:
  INSERT INTO Person (Name, Age ) VALUES ('Frost', NULL)
  And pass it to the engine.



-- 
Best regards,
Ivan Smahin 
Senior Software Engineer
Paradigma Software, Inc
Valentina - The Ultra-Fast Database
http://www.valentina-db.com




More information about the Valentina mailing list