PHP Tutorial How to connect MS SQL Server Database Tutorial
The following is connected to the MSSQL Server database code.
<?php
$myServer = "localhost";
$myUser = "Your_Name";
$myPass = "Your_password";
$myDB = "examples";
Connection to the database
$dbhandle = Mssql_connect ($myServer, $myUser, $myPass)
Or Die ("couldn ' t connect to SQL Server on $myServer");
Select a database to work with
$selected = mssql_select_db ($myDB, $dbhandle)
Or Die ("couldn ' t Open database $myDB");
Declare the SQL statement that'll query the database
$query = "SELECT ID, name, year";
$query. = "From cars";
$query. = "WHERE name= ' BMW '";
Execute the SQL query and return records
$result = Mssql_query ($query);
$numRows = Mssql_num_rows ($result);
echo "
Display the results
while ($row = Mssql_fetch_array ($result))
{
echo "<li>". $row ["id"]. $row [' name ']. $row ["Year"]. "</li>";
}
Close the connection
Mssql_close ($dbhandle);
?>
DSN's assertion ' data source name '. This is an easy way to allocate, easily rememberable useful data
The name of the source may not be limited to a separate database. If you don't know how to build a System DSN read our
Tutorial How to create a System DSN.
In the following example, we will show you how to use a MSSQL server database DSN called ' connection
Examples.mdb ' and retrieves all the ' cars ' in the record table.
<?php
Connect to a DSN "MyDSN"
$conn = Odbc_connect (' MyDSN ', ', ', ');
if ($conn)
{
The SQL statement that would query the database
$query = "SELECT * from Cars";
Perform the query
$result =odbc_exec ($conn, $query);
echo "<table border=" 1 "><tr>";
Print Field name
$colName = Odbc_num_fields ($result);
for ($j =1; $j <= $colName; $j + +)
{
echo "<th>";
Echo Odbc_field_name ($result, $j);
echo "</th>";
}
Fetch tha data from the database
while (Odbc_fetch_row ($result))
{
echo "<tr>";
for ($i =1; $i <=odbc_num_fields ($result); $i + +)
{
echo "<td>";
Echo Odbc_result ($result, $i);
echo "</td>";
}
echo "</tr>";
}
echo "</td> </tr>";
echo "</table >";
Close the connection
Odbc_close ($conn);
}
else echo "ODBC not Connected";
?>
=======================
How PHP converts PDF files into txt text files
Document Format (PDF) is a file exchange created in file format. Each PDF file encapsulates a fixed layout
Full description of the 2D file (and, with Acrobat 3D software, embedded 3D file), which includes text, Word
Body, image and two-dimensional vector graphics, compose files.
function Pdf2text ($filename) {
Read the data from PDF file
$infile = @file_get_contents ($filename, file_binary);
if (empty ($infile))
Return "";
Get all text data.
$transformations = Array ();
$texts = Array ();
Get the list of all objects.
Preg_match_all ("#obj (. *) Endobj#ismu", $infile, $objects);
$objects = @ $objects [1];
Select objects with streams.
for ($i = 0; $i < count ($objects); $i + +) {
$currentObject = $objects [$i];
Check If an object includes data stream.
if (Preg_match ("#stream (. *) Endstream#ismu", $currentObject,
$stream)) {
$stream = LTrim ($stream [1]);
Check object parameters and look for text data.
$options = Getobjectoptions ($currentObject);
if (!) ( Empty ($options ["Length1"]) && empty ($options ["Type"]) &&
Empty ($options ["subtype"]))
Continue
//So, we have text data. Decode it.
$data = Getdecodedstream ($stream, $options) ;
if (strlen ($data)) {
if (Preg_match_all ("#BT (. *) Et#ismu ", $data,
$textContainers)) {
$textContainers = @ $textContainers [1];
Getdirtytexts ($texts, $textContainers);
} else
Getchartransformations ($transformations, $data);
}
}
}
Analyze text blocks taking into account character transformations
and return results.
return gettextusingtransformations ($texts, $transformations);
}