- Обновление таблицы БД из XML файлов
- Чтение стандартного XML файла
- Пример файла:
- Чтение файла и обновление записей в БД:
- XML файл из 1С
- Saved searches
- Use saved searches to filter your results more quickly
- iandecroix/pdo-xml-php-extension
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README
- About
- Import XML Data into Mysql Database (Ajax, PHP and PDO)
- Import XML Data into Mysql Database (Ajax, PHP and PDO)
Обновление таблицы БД из XML файлов
Два примера чтения xml файлов, которые обновляют цены и остатки в базе данных интернет магазина.
Чтение стандартного XML файла
Пример файла:
105AG 105AG "Ангел" Ночник 0 483.00 105BB 105BB "Медведь" Ночник 40 39.00 .
Чтение файла и обновление записей в БД:
Для доступа к БД используется библиотека PDO MySQL.
// Подключение к БД. $dbh = new PDO('mysql:dbname=НАЗВАНИЕ_БД;host=localhost', 'ЛОГИН', 'ПАРОЛЬ'); $data = simplexml_load_file('http://site.com/file.xml'); foreach ($data->item as $row) < $articool = strval($row->article); $stock = intval($row->stock); $price = floatval($row->price); // Поиск товара в БД по артикулу. $sth = $dbh->prepare("SELECT * FROM `prods` WHERE `articool` = ?"); $sth->execute(array($articool)); $prod = $sth->fetch(PDO::FETCH_ASSOC); // Обновление товара. if (!empty($prod)) < $sth = $dbh->prepare("UPDATE `prods` SET `price` = ?, `stock` = ? WHERE `id` = ?"); $sth->execute(array($price, $stock, $prod['id'])); > >
XML файл из 1С
1C формирует файлы с использованием кириллицы и значения хранятся в атрибутах элементов:
// Подключение к БД. $dbh = new PDO('mysql:dbname=НАЗВАНИЕ_БД;host=localhost', 'ЛОГИН', 'ПАРОЛЬ'); $data = simplexml_load_file('http://site.com/file_1c.xml'); foreach ($data->item as $row) < $articool = strval($row->Артикул['Артикул']); $stock = intval($row->Остаток['Остаток']); $price = floatval($row->Цены['Розничная']); // Поиск товара в БД по артикулу. $sth = $dbh->prepare("SELECT * FROM `prods` WHERE `articool` = ?"); $sth->execute(array($articool)); $prod = $sth->fetch(PDO::FETCH_ASSOC); // Обновление товара. if (!empty($prod)) < $sth = $dbh->prepare("UPDATE `prods` SET `price` = ?, `stock` = ? WHERE `id` = ?"); $sth->execute(array($price, $stock, $prod['id'])); > >
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
Automatically exported from code.google.com/p/pdo-xml-php-extension
iandecroix/pdo-xml-php-extension
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README
This is a standalone PHP extension created using CodeGen_PECL 1.1.2 Author: SOFTPAE.com Please, make an link to SOFTPAE.com from your website. Thanks. HACKING ======= There are two ways to modify an extension created using CodeGen_PECL: 1) you can modify the generated code as with any other PHP extension 2) you can add custom code to the CodeGen_PECL XML source and re-run pecl-gen The 2nd approach may look a bit complicated but you have be aware that any manual changes to the generated code will be lost if you ever change the XML specs and re-run PECL-Gen. All changes done before have to be applied to the newly generated code again. Adding code snippets to the XML source itself on the other hand may be a bit more complicated but this way your custom code will always be in the generated code no matter how often you rerun CodeGen_PECL. BUILDING ON UNIX etc. ===================== To compile your new extension, you will have to execute the following steps: 1. $ ./phpize 2. $ ./configure [--enable--pdo_xml] 3. $ make 4. $ make test 5. $ [sudo] make install BUILDING ON WINDOWS =================== The extension provides the VisualStudio V6 project file pdo_xml.dsp To compile the extension you open this file using VisualStudio, select the apropriate configuration for your installation (either "Release_TS" or "Debug_TS") and create "php_pdo_xml.dll" After successfull compilation you have to copy the newly created "pdo_xml.dll" to the PHP extension directory (default: C:\PHP\extensions). TESTING ======= You can now load the extension using a php.ini directive extension="pdo_xml.[so|dll]" or load it at runtime using the dl() function dl("pdo_xml.[so|dll]"); The extension should now be available, you can test this using the extension_loaded() function: if (extension_loaded("pdo_xml")) echo "pdo_xml loaded :)"; else echo "something is wrong :("; The extension will also add its own block to the output of phpinfo();
About
Automatically exported from code.google.com/p/pdo-xml-php-extension
Import XML Data into Mysql Database (Ajax, PHP and PDO)
In this article, we are going to know how to Import XML Data into Mysql Database table by using PHP code with Ajax. We all know XML stands for eXtensible Markup Language and it is used for to save and read data on the web and this data readable format for human and machine also. This type of data essentially handled for transfer data from one platform to another platform on the internet and it is also compatible with all programming language.
We can define XML data as very easy by user-defined tag format with a data value and it contains both opening and closing tag as the same name. For example this is the format for a user-defined custom tag with an XML file.
For Import or Insert XML file data into MySQL database table, so we create a simple form for uploading XML file to the server and here we have some file format validation for upload only XML file. After creating HTML form content we want to pass XML file to the server, so here we use jQuery Ajax request to the server for further import process using PHP. In Ajax, we use FormData() for submitting the form data into server-side script page. In server-side script we use simplexml_load_file() method to read data from selected XML file and pass into our MySQL database one by one.
Step 1: Database and Connect Details
Here we going to get contention with MySQL database using PHP with PDO contention property. Using this contention object we can process the Importing XML data to MySQL database table.
Import XML Data into Mysql Database (Ajax, PHP and PDO)
In this article, we are going to know how to Import XML Data into Mysql Database table by using PHP code with Ajax. We all know XML stands for eXtensible Markup Language and it is used for to save and read data on the web and this data readable format for human and machine also. This type of data essentially handled for transfer data from one platform to another platform on the internet and it is also compatible with all programming language.
We can define XML data as very easy by user-defined tag format with a data value and it contains both opening and closing tag as the same name. For example this is the format for a user-defined custom tag with an XML file.
For Import or Insert XML file data into MySQL database table, so we create a simple form for uploading XML file to the server and here we have some file format validation for upload only XML file. After creating HTML form content we want to pass XML file to the server, so here we use jQuery Ajax request to the server for further import process using PHP. In Ajax, we use FormData() for submitting the form data into server-side script page. In server-side script we use simplexml_load_file() method to read data from selected XML file and pass into our MySQL database one by one.
Step 1: Database and Connect Details
Here we going to get contention with MySQL database using PHP with PDO contention property. Using this contention object we can process the Importing XML data to MySQL database table.