How to load .mdb file into mysql database using php code.
I have a .mdb file and location is /example/employee.mdb. I need to read record from attendance table and insert it into mysql's emp_attendance table.
What will be PHP logic for that?
Like most relational databases, PHP can connect to MS Access and MySQL with PDO. Consider doing so with a dual connection with MySQL. No external, third-party software is required. Below example uses a mock table and fields. Adjust as needed:
Requirements include (no MSAccess.exe installation required):
php_pdo.dll extension enabled in .ini file
MS Access ODBC Driver (usually already pre-installed)
Any Windows PC (pre-built with Jet/ACE SQL engine -Access' underlying engine)
PHP Dual PDO Connection
$accdatabase="C:\Path\To\database.accdb";
$host="localhost";
$mydatabase="****";
$username="****";
$password="****";
try {
# OPEN BOTH DATABASE CONNECTIONS
$accConn = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)}; DBq=$accdatabase;Uid=Admin;Pwd=;");
$myConn = new PDO("mysql:host=$host;dbname=$mydatabase",$username,$password);
$myConn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "SELECT * FROM emp_attendance";
$accstmt = $accConn->query($sql);
$accstmt->setFetchMode(PDO::FETCH_ASSOC);
// FETCH ROWS FROM MS ACCESS
while($row = $accstmt->fetch()) {
// APPEND TO MYSQL
$mystmt = $myConn->prepare("INSERT INTO emp_attendance (empid, `date`, status, notes) VALUES (?, ?, ?, ?)");
# BIND PARAMETERS
$mystmt->bindParam(1, $row['empid'], PDO::PARAM_STR, 50);
$mystmt->bindParam(2, $row['date'], PDO::PARAM_STR, 50);
$mystmt->bindParam(3, $row['status'], PDO::PARAM_STR, 50);
$mystmt->bindParam(4, $row['notes'], PDO::PARAM_STR, 50);
# EXECUTE QUERY
$mystmt->execute();
}
}
catch(PDOException $e) {
echo $e->getMessage()."\n";
exit;
}
// CLOSE CONNECTIONS
$accConn = null;
$myConn = null;
Finally Below logic worked for me.
$fileNm = "C:\Users\abc\Desktop\attendanceData.mdb";
$conn = new COM("ADODB.Connection") or die("ADODB Connection Faild!");
$conn->Open("DRIVER={Microsoft Access Driver (*.mdb)};DBQ=$fileNm");
if($conn){
$data = $conn->Execute("SELECT * FROM em_attendance");
}
read the data from mdb to csv
read from csv and insert into mysql
Or
Try this
http://board.phpbuilder.com/showthread.php?10365863-Convert-mdb-to-mysql
MDB is a database file used by Microsoft Access. MDB is Access’s own
format which is based on the Access Jet Database Engine. You can open
it by Microsoft Access as it is it's own format, also can open it by
Microsoft Excel, If you don't have Microsoft Office you don't need to
worry about. MDB files can also be opened by OpenOffice.org, SAS
Institute SAS, Wolfram Mathematica, Softpedia MDB Converter¸ and
Microsoft Visual Studio 2010. MDB file files can be converted to .TXT
or .CSV formats using a MDB Converter. Even if you don't have above
all you can download the a free popular tool MDB Viewer Plus
(http://download.cnet.com/MDB-Viewer-Plus/3001-10254_4-75285626.html?onid=10254)
Read datas and insert into database however you want. Better convert the file mdb to csv and insert into database. It's easier using by PHP. Hope you have your answer
Steps to Convert Microsoft Access Files to CSV Format
Open the MDB file with Microsoft access to export to a CSV format
Click on the ‘External Data’ tab
Select ‘Excel’ from the Export section
“Select the destination for the data you want to export”
Choose an appropriate file name and location
Select Excel Workbook as the file format
Specify the appropriate export options
Hit the ‘OK’ button
Open the file you just saved using Microsoft Excel
Select File and ‘Save As’
Click the drop-down next to ‘Save as type:’
Change the ‘Save as type’ to ‘CSV (Comma delimited)(*.csv)’
Choose an appropriate ‘File name’
‘Save’ to your desktop
Hope your problem will be solved.Thanks
Related
I have a blob which we receive from a Firebird 3.0 database.
if($dbh = ibase_connect($db,$username,$password, 'UTF-8')){
echo "Connecton steht zur Firebird DB steht! <br>";
$sql = "SELECT MEMO FROM DMS where ID = '44'";
// Execute query
$rc = ibase_query($dbh, $sql);
// Get the result row by row as object
$data = ibase_fetch_object($rc);
$blob_data = ibase_blob_info($data->MEMO);
$blob_hndl = ibase_blob_open($data->MEMO);
$inhalt = ibase_blob_get($blob_hndl, $blob_data[0]);
With
ibase_blob_echo($data->MEMO)
there comes a lot of signs in browser, so the SQL query works. Now I'd like to write the content (its a PDF) in a pdf file on disk.
Every try didn't succeed:
file_put_contents('test.pdf', $inhalt);
file_put_contents('test.pdf', ibase_blob_echo($data->MEMO));
and much more.
When we try to open the PDF File with Acrobat Reader, there comes an error message: no PDF File / File-type is not supported
How can we fix this?
thank you for your answers ... We interpreted them in a way, that the code above is basicly correct. After a while, we found out, that the error apears because we changed the charset in the DB Connect to UTF8 for the varchar Fields. For the blob we connect now without Charset change and the readout work properly. Thank you again.
$dbh = ibase_connect($db,$username,$password)
I am new to Crystal Reports, and I am using version Crystal Reports 11.5.
My requirement is as below:
Programming Environment is PHP .
Database is MySQL.
I want to generate PDF reports using Crystal Report + PHP + MySQL.
Currently, I am using COM object to connect to Crystal Report using PHP, and I am able to generate a sample static PDF report.
My main task is to do all processing in PHP by fetching values from MySQL and pass the values to Crystal Reports and generate a PDF. I need assistance to achieve this task. If anybody can provide sample code then it will be much better.
This is what I have so far:
$my_report = "E:\\xampp\\htdocs\\crystal\\Test1.rpt";
$my_pdf = "E:\\xampp\\htdocs\\crystal\\test.pdf";
$o_CrObjectFactory = new COM('CrystalReports11.ObjectFactory.1');
// Create the Crystal Reports Runtime Application.
$o_CrApplication =$o_CrObjectFactory->CreateObject("CrystalDesignRunTime.Application");
//------ Open your rpt file ------
$creport = $o_CrApplication->OpenReport($my_report, 1);
//------ Connect to DB2 DataBase ------
**this is the hard part where I am not able to complete connection to mysql**
$o_CrApplication->LogOnServer('which library','mlims','root','');
//------ Put the values that you want --------
$creport->RecordSelectionFormula="{parameter.id}='1'";
//------ This is very important. DiscardSavedData make a
// Refresh in your data -------
$creport->DiscardSavedData;
//------ Read the records :-P -------
$creport->ReadRecords();
//------ Export to PDF -------
$creport->ExportOptions->DiskFileName=$my_pdf;
$creport->ExportOptions->FormatType=31;
$creport->ExportOptions->DestinationType=1;
$creport->Export(false);
//------ Release the variables
$creport = null;
$crapp = null;
$ObjectFactory = null;
As you see In the above code, I need to connect the Mysql server which I have been trying to do for the last few days. I have tried many examples on the net, but most of them are for SQL Server, not MySQL.
Please follow the steps:
Download the MySQL Connector J jar file. That download should contain a jar file that looks something like:
mysql-connector-java-3.1.14-bin.jar
Add the location of your newly downloaded jar file to the Classpath, as defined in CrystalReports CRConfig.xml file. On a Windows machine, the config file will be located somewhere like:
C:\Program Files\Business Objects\Common\3.5\java\CRConfig.xml
Once you have altered your CRConfig.xml, close and reopen Crystal Reports.
From the menu: File -> New -> Standard Report
In the “Available Data Sources” list, double-click to expand “Create New Connection”
Double-click to expand “JDBC (JNDI)”
Double-click “Make New Connection”
Connection URL: “jdbc:mysql://db.example.com/dbname” (Use your own database host name and db name).
Database Classname: “com.mysql.jdbc.Driver”
Click “Next”
Enter a database user/password combination when prompted.
You should now be able to inspect the tables/columns in the database to begin reporting.
See reference
We have asoftware engineering project i need to put picture in the database using blob of php interbase using firebird server. Could someone give me some reerences to do it. Or some example?
Regards.
First create a method call insertBlob or name it anything you want.
then open the file as binary, 'rb' means read binary so you can save it to your database as a blob type.
public function insertBlob($filePath,$mime){
$blob = fopen($filePath,'rb');
$sql = "INSERT INTO files(mime,data) VALUES(:mime,:data)";
$stmt = $this->conn->prepare($sql);
$stmt->bindParam(':mime',$mime);
$stmt->bindParam(':data',$blob,PDO::PARAM_LOB);
return $stmt->execute();
}
now you can do somethiling like this..
insertBlob('C:/picture1.png','image/png');
I have a file in xls format that I need to refresh (use 'refresh all' button in Excel) once a day and then retrieve the data from the pivot table and inset them into the database (MySQL). The file gets data from an external source (retrieve data from sharepoint 2007).
How is the easiest way to do this?
I'm thinking abaout PHP but do I not quite know how you go about it. From what I read PHPExcel does not support this operations.
When you try to use COM I get an error:
Fatal error: in D:\xampp\htdocs\sp\xls\index.php on line 11
And here is a php code:
<?php
// Start Excel
$excel = new COM("Excel.Application") or die ("Could not load Excel.Application");
// Make Excel visible.
$excel->Application->Visible = 1;
// Open workbook
$Workbook = $excel->Workbooks->Open('D:/xampp/htdocs/sp/xls/emails.xls', 'r+') ;
// Refresh all
$Workbook->RefreshAll();
// Save updated excel file out to disk somewhere
$Workbook->SaveAs('D:/xampp/htdocs/sp/xls/emails.xls');
// Close all instances of excel:
$Workbook->Close(false);
unset($Workbook);
$excel->Workbooks->Close();
$excel->Quit();
unset($excel);
?>
I'm using windows 7 and xampp with php 5.5.6
In php.ini I've added this line:
extension=php_com_dotnet.dll
Alternate: is it possible to run *.iqy file generated by sharepoint in php?
I found a workaround to my problem.
Instead, refresh the data by PHP pointed out in a query that collects data during the re-launch of the sheet. To this I added this VBA script save changes and close file.
At the end of the added task scheduler to run the sheet once per day.
The rest of downloading data from Excel using PHPExcel.
I have a database table to store my templates(.docx file). I am using openTbs to work on that templates.My need is that to take out the template and store it in thee server itself, and edit using openTbs.
My question is that how I can retrieve .docx file from database and store that in the server side.? (The storing may be temporary but i want to edit it using openTbs.)
Thanks in advance.......
It is bad practice to save binary data in the database, mostly when this data are intend to be processed by a file server, such as pictures or your DOCX.
Anyway, since OpenTBS 1.8.1, you can open an DOCX (or any Ms Office, LibreOffie or zip archive) from a PHP file handle.
You can use this feature to easily merge your template from the database :
// retrieve binary data of the file
$rs = mysql_query($dbc, "SELECT data FROM files WHERE id=$id");
$rec= mysql_fetch_array($rs, MYSQLI_ASSOC);
mysql_free($rs);
// create a temporary file
$temp = tmpfile();
fwrite($temp, $rec['file']);
unset($rec); // free PHP memory
// Open the file with OpenTBS
$TBS = new clsTinyButStrong;
$TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN);
$TBS->LoadTemplate($temp);
...