note 57379 added to function.mssql-query
| From: | abelzelda at yahoo dot es | Date: | Sun, 02 Oct 2005 00:26:30 +0000 |
| Subject: | note 57379 added to function.mssql-query | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-96154@lists.php.net to get a copy of this message | ||
Here it's a very easy way to insert image into a
SQL SERVER using PHP
-First:
Create formulary.php:
//---------------------------------------------------------------
<HTML>
<HEAD>
<TITLE>Binary to DB</TITLE>
</HEAD>
<BODY>
<FORM enctype="multipart/form-data" method="post"
action="../Pages/insert.php">
Archivo: <INPUT type="file" name="archivo" size="30">
<INPUT type="submit" name="submit" value="Subir archivo">
</FORM>
</BODY>
</HTML>
//---------------------------------------------------------------
-Second:
Create insert.php
//--------------------------------------------------------------
<?php
// Check if it was loaded an is correct.
if (empty($_FILES['file']['name'])){
header("location:../Pages/formulary.php?process=
mising_indicated_file"); //whenever formulary is called ..
exit;
}
//Entablish conexion with data base.
require("../adodb/adodb.inc.php");// using ADO DB Data POWER
$conexion =& ADONewConnection('odbc_mssql');
$dsn = "Driver={SQL Server};Server=Server;Database=DB;";
$conexion->Connect($dsn,'user','password');
// Temp file (ruta y nombre).
$binary_name_temp=$_FILES['file']['tmp_name'] ;
//The MSSQL documentation states that binary constants should be represented by their unquoted
hexadecimal byte-string. That is.. to set the binary column "col" to contain the bytes
0x12, 0x65 and 0x35 you shold do "col = 0x126535" in you query.
$datastring = file_get_contents($binary_name_temp);
$data = unpack("H*hex", $datastring);
$sql = "insert into Table (Image)
values (0x".$data['hex'].")";
$recordSet = $conexion->Execute($sql);
if (!$recordSet)
print $conexion->ErrorMsg();
else
{}
//Close the conexion
$recordSet->Close();
$conexion->Close();
?>
Done !!!!!!!!!!!!!!!!!!
Enjoy :D :D :D :D :D
//From Cuba to the people//
----
Manual Page -- http://www.php.net/manual/en/function.mssql-query.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+57379
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57379&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57379&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57379&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57379&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57379&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57379&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57379&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+57379&report=yes
Search -- http://master.php.net/manage/user-notes.php