René Nyffenegger's collection of things on the web
René Nyffenegger on Oracle - Most wanted - Feedback -
 

insert [MySQL and PHP]

create table table_ex (
  i   integer,
  t   varchar(20),
  b   blob
);
<?php

  function insert_table_ex($i, $t, $b) {
    $stmt =  'insert into table_ex values (' .
             mysql_real_escape_string($i) .   ', ' .
      '\'' . mysql_real_escape_string($t) . '\', ' .
      '\'' . mysql_real_escape_string($b) . '\')';

    if (!mysql_query($stmt)) {
      printf("Could not insert: <b>%s</b>", mysql_error());
    }

  }

  require('conn_db.inc');

  $db_conn = connect_db();

  if ($db_conn) {
    insert_table_ex(
          42,
         'fourty-two',
         'This should be a blob with \'quotes\' and \\backslashes\\'
    );

    insert_table_ex(
          9,
         'nine',
         'some &amp; special <html> things'
    );


  }

?>