database Archives - David Yin's Blog https://www.yinfor.com/tag/database Tech geek. Life geek. Fri, 15 Nov 2019 07:21:26 +0000 en-US hourly 1 https://wordpress.org/?v=6.7.1 https://www.yinfor.com/wp-content/uploads/2016/09/cropped-icon-120x120.png database Archives - David Yin's Blog https://www.yinfor.com/tag/database 32 32 Make the PHP support Microsoft Access MDB file on Ubuntu 18.04 https://www.yinfor.com/2019/11/make-the-php-support-microsoft-access-mdb-file-on-ubuntu-18-04.html https://www.yinfor.com/2019/11/make-the-php-support-microsoft-access-mdb-file-on-ubuntu-18-04.html#respond Fri, 15 Nov 2019 07:21:26 +0000 https://www.yinfor.com/?p=7080 The very first step is to prepare the Ubuntu server. I installed the Ubuntu 18.04 on a VM with 1CPU, 1024MB memory and 16GB storage room. After the installation. Start the Ubuntu server and ssh to it. Run the following...

The post Make the PHP support Microsoft Access MDB file on Ubuntu 18.04 appeared first on David Yin's Blog.

]]>
The very first step is to prepare the Ubuntu server.

I installed the Ubuntu 18.04 on a VM with 1CPU, 1024MB memory and 16GB storage room.

After the installation. Start the Ubuntu server and ssh to it.

Run the following command to keep it all updated.

sudo apt update
sudo apt upgrade

There is about 254 packages need to be upgraded.

Now it is time to start the installation.

Install Nginx web server, Mariadb server, php 7.2 support.

sudo apt install nginx
sudo apt install mariadb-server
sudo mysql-secure-installation
sudo apt install php7.2 php7.2-fpm php7.2-cli php7.2-common php7.2-mbstring php7.2-gd php7.2-intl php7.2-xml php7.2-mysql php7.2-zip php7.2-json php7.2-curl

First, regarding nginx.

davidyin@php-mdb:~$ sudo apt install nginx
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
fontconfig-config fonts-dejavu-core libfontconfig1 libgd3 libjbig0
libjpeg-turbo8 libjpeg8 libnginx-mod-http-geoip
libnginx-mod-http-image-filter libnginx-mod-http-xslt-filter
libnginx-mod-mail libnginx-mod-stream libtiff5 libwebp6 libxpm4 nginx-common
nginx-core
Suggested packages:
libgd-tools fcgiwrap nginx-doc ssl-cert
The following NEW packages will be installed:
fontconfig-config fonts-dejavu-core libfontconfig1 libgd3 libjbig0
libjpeg-turbo8 libjpeg8 libnginx-mod-http-geoip
libnginx-mod-http-image-filter libnginx-mod-http-xslt-filter
libnginx-mod-mail libnginx-mod-stream libtiff5 libwebp6 libxpm4 nginx
nginx-common nginx-core
0 upgraded, 18 newly installed, 0 to remove and 0 not upgraded.
Need to get 2,461 kB of archives.
After this operation, 8,210 kB of additional disk space will be used.
Do you want to continue? [Y/n]

Regarding MariaDB installation

davidyin@php-mdb:~$ sudo apt install mariadb-server
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
galera-3 libaio1 libcgi-fast-perl libcgi-pm-perl libconfig-inifiles-perl
libdbd-mysql-perl libdbi-perl libencode-locale-perl libfcgi-perl
libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl
libhttp-date-perl libhttp-message-perl libio-html-perl libjemalloc1
liblwp-mediatypes-perl libmysqlclient20 libterm-readkey-perl
libtimedate-perl liburi-perl mariadb-client-10.1 mariadb-client-core-10.1
mariadb-common mariadb-server-10.1 mariadb-server-core-10.1 mysql-common
socat
Suggested packages:
libclone-perl libmldbm-perl libnet-daemon-perl libsql-statement-perl
libdata-dump-perl libipc-sharedcache-perl libwww-perl mailx mariadb-test
tinyca
The following NEW packages will be installed:
galera-3 libaio1 libcgi-fast-perl libcgi-pm-perl libconfig-inifiles-perl
libdbd-mysql-perl libdbi-perl libencode-locale-perl libfcgi-perl
libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl
libhttp-date-perl libhttp-message-perl libio-html-perl libjemalloc1
liblwp-mediatypes-perl libmysqlclient20 libterm-readkey-perl
libtimedate-perl liburi-perl mariadb-client-10.1 mariadb-client-core-10.1
mariadb-common mariadb-server mariadb-server-10.1 mariadb-server-core-10.1
mysql-common socat
0 upgraded, 29 newly installed, 0 to remove and 0 not upgraded.
Need to get 24.2 MB of archives.
After this operation, 184 MB of additional disk space will be used.
Do you want to continue? [Y/n]

Add root user password to MariaDB

davidyin@php-mdb:~$ sudo mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n]
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n]
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n]
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n]
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n]
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
davidyin@php-mdb:~$

Install php7.2-fpm

 

davidyin@php-mdb:~$ sudo apt install php7.2 php7.2-fpm php7.2-cli php7.2-common php7.2-mbstring php7.2-gd php7.2-intl php7.2-xml php7.2-mysql php7.2-zip php7.2-json php7.2-curl
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  libsodium23 libzip4 php-common php7.2-opcache php7.2-readline
Suggested packages:
  php-pear
The following NEW packages will be installed:
  libsodium23 libzip4 php-common php7.2 php7.2-cli php7.2-common php7.2-curl
  php7.2-fpm php7.2-gd php7.2-intl php7.2-json php7.2-mbstring php7.2-mysql
  php7.2-opcache php7.2-readline php7.2-xml php7.2-zip
0 upgraded, 17 newly installed, 0 to remove and 0 not upgraded.
Need to get 5,015 kB of archives.
After this operation, 21.3 MB of additional disk space will be used.
Do you want to continue? [Y/n]

After that, fix the potential problem of connection with phpmyadmin

Setup the Nginx site

cd /etc/nginx/conf.d/
sudo nano mysite.conf

Paste the these code into the file and save it.
Run the following command to test the Nginx configuration and restart the Nginx service.

sudo nginx -t
sudo service nginx restart

Add a phpinfo page to test

cd ~
mkdir mysite.com
cd mysite.com
nano phpinfo.php

Add the following php code.

phpinfo();

In the browser, enter the address http://mysite.com/phpinfo.php

Install mdbtools etc.

sudo apt install mdbtools unixodbc odbc-mdbtools unixodbc-bin php7.2-odbc
sudo service php7.2-fpm restart

Then I upload the a Microsoft Access MDB file, sample.mdb and a mdb.php file.
This database file has a table, pt_users, which has two fields of user’s first name and last name. I will retrieve them.
The content of mdb.php as below:

$db = './sample.mdb';

$dbName  =  $db  ; 
$driver  =  'MDBTools'; 

$dbh  =  new  PDO("odbc:Driver=$driver;DBQ=$dbName;");
	
// Table with column num, name test 
   $sql  =  "SELECT userfirstname, userlastname FROM pt_users" ;  // The rules are the same as above 
   $sth  =  $dbh ->  prepare($sql); 
   $sth ->  execute(); 
   // Bind to each column 
   $sth ->  bindColumn(1,$fname); 
   $sth ->  bindColumn(2,$lname);

   // Because of binding to the column, only the judgment result will be returned to $ flg 
   $values  =  [];  // Array to assign the value 
   while (  $flg  =  $sth ->  fetch(PDO::FETCH_BOUND)){ 
             $values[]  =  [$fname,$lname ]; 
	   	echo $fname,' :  ',$lname,'
';
   }	

I got blank page and check the Nginx error log file at /var/log/nginx/error.log

2019/11/15 06:55:53 [error] 28826#28826: *7 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught PDOException: SQLSTATE[01000] SQLDriverConnect: 0 [unixODBC][Driver Manager]Can't open cursor lib '/etc/libodbccr.so' : file no$
Stack trace:
#0 /home/davidyin/mysite.com/mdb.php(18): PDO->__construct('odbc:Driver=MDB...')
#1 {main}
thrown in /home/davidyin/mysite.com/mdb.php on line 18" while reading response header from upstream, client: 192.168.1.3, server: mysite.com, request: "GET /mdb.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.2-fpm.sock:", $

It said missing libodbccr.so.
Run the following command.

cd /usr/lib/x86_64-linux-gnu
sudo ln libodbccr.so.2 libodbccr.so

Then Reload the http://mysite.com/mdb.php
Got the correct result. Done.

 

At last, the environment:

  • Ubuntu 18.04.3 LTS
  • Nginx 1.14.0
  • php 7.2.24
  • MariaDB 10.1.41

The post Make the PHP support Microsoft Access MDB file on Ubuntu 18.04 appeared first on David Yin's Blog.

]]>
https://www.yinfor.com/2019/11/make-the-php-support-microsoft-access-mdb-file-on-ubuntu-18-04.html/feed/ 0
Use Adminer to manage the MySQL database https://www.yinfor.com/2019/03/use-adminer-to-manage-the-mysql-database.html https://www.yinfor.com/2019/03/use-adminer-to-manage-the-mysql-database.html#respond Thu, 28 Mar 2019 08:12:46 +0000 https://www.yinfor.com/?p=6800 I am used to using phpmyadmin to manage the MySQL database for many years. Just recently, I saw an alternative way to do it. Adminer,  a full-featured database management tool written in PHP. The latest version is v4.7.1 when I...

The post Use Adminer to manage the MySQL database appeared first on David Yin's Blog.

]]>
I am used to using phpmyadmin to manage the MySQL database for many years. Just recently, I saw an alternative way to do it. Adminer,  a full-featured database management tool written in PHP.

Official site of Adminer

The latest version is v4.7.1 when I write this post.

Features

  • Connect to a database server with username and password
  • Select an existing database or create a new one
  • List fields, indexes, foreign keys and triggers of table
  • Change name, engine, collation, auto_increment and comment of table
  • Alter name, type, collation, comment and default values of columns
  • Add and drop tables and columns
  • Create, alter, drop and search by indexes including fulltext
  • Create, alter, drop and link lists by foreign keys
  • Create, alter, drop and select from views
  • Create, alter, drop and call stored procedures and functions
  • Create, alter and drop triggers
  • List data in tables with search, aggregate, sort and limit results
  • Insert new records, update and delete the existing ones
  • Supports all data types, blobs through file transfer
  • Execute any SQL command from a text field or a file
  • Export table structure, data, views, routines, databases to SQL or CSV
  • Print database schema connected by foreign keys
  • Show processes and kill them
  • Display users and rights and change them
  • Display variables with links to documentation
  • Manage events and table partitions (MySQL 5.1)
  • Schemas, sequences, user types (PostgreSQL)
  • Extensive customization options

It is a single file program. Include multiple language. You can download it from the official site here.

The post Use Adminer to manage the MySQL database appeared first on David Yin's Blog.

]]>
https://www.yinfor.com/2019/03/use-adminer-to-manage-the-mysql-database.html/feed/ 0
Convert MyISAM tables to InnoDB without Touching Data https://www.yinfor.com/2014/02/convert-myisam-tables-to-innodb-without-touching-data.html https://www.yinfor.com/2014/02/convert-myisam-tables-to-innodb-without-touching-data.html#respond Wed, 26 Feb 2014 02:18:06 +0000 https://www.yinfor.com/?p=3414 It is a smoothly converting without hurting data inside of the tables. I have phpmyadmin installation on my VPS. So just goto there and select database, click SQL tab of it. Enter following sql and click Go. ALTER TABLE tablename...

The post Convert MyISAM tables to InnoDB without Touching Data appeared first on David Yin's Blog.

]]>
It is a smoothly converting without hurting data inside of the tables.

I have phpmyadmin installation on my VPS. So just goto there and select database, click SQL tab of it.

Enter following sql and click Go.

ALTER TABLE tablename ENGINE = INNODB;

alter-tables-engine

If the table is large, then it may take a while to convert it over. There will probably be a fair amount of CPU usage and disk I/O in the process. In my case, I do not feel the delay when I click Go button.

There are also some script can help you alter all tables. Then, you don’t have to type sql command for each table, if you have hundred tables of databases.

<?php
    // connect your database here first
    //

    // Actual code starts here

    $sql = "SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE engine <> 'InnoDB'";
    $rs = mysql_query($sql);

    while($row = mysql_fetch_array($rs))
    {
        $tbl = $row[0];
        $sql = "ALTER TABLE $tbl ENGINE=INNODB";
        mysql_query($sql);
    }
?>

Save above php script into a php file into your web server. Modify the database connection portion. Then run this script from your browser. It will do all the job for you.

Some help from Major.

The post Convert MyISAM tables to InnoDB without Touching Data appeared first on David Yin's Blog.

]]>
https://www.yinfor.com/2014/02/convert-myisam-tables-to-innodb-without-touching-data.html/feed/ 0
Classic ASP program with Access database on Windows server 2008 https://www.yinfor.com/2013/11/classic-asp-program-with-access-database-on-windows-server-2008.html https://www.yinfor.com/2013/11/classic-asp-program-with-access-database-on-windows-server-2008.html#respond Fri, 15 Nov 2013 09:27:12 +0000 https://www.yinfor.com/?p=1408 Got error 800a0cb3 from the Web log file at Windows Server 2008. It is IIS7. The Web application is made by ASP. Actually classic ASP, not ASP.Net. And also with Access database.  The page is try to add new record...

The post Classic ASP program with Access database on Windows server 2008 appeared first on David Yin's Blog.

]]>
Got error 800a0cb3 from the Web log file at Windows Server 2008. It is IIS7. The Web application is made by ASP. Actually classic ASP, not ASP.Net.

And also with Access database.  The page is try to add new record into the Access database file. But the browser return 500 internal error. The detail error code in log file is 800a0cb3 with the description: Recordset does not support updating. This may be a limitation of the provider or of the selected locktype.

I did a lot of research and found it is a right issue.

Now it is the solution:

Add “Authenticated Users” to the Access mdb file, with full access right.

access-win2008-permission

Then, no more error, the data can be added as design.

The post Classic ASP program with Access database on Windows server 2008 appeared first on David Yin's Blog.

]]>
https://www.yinfor.com/2013/11/classic-asp-program-with-access-database-on-windows-server-2008.html/feed/ 0
How to fix the error of collating sequence not supported with the specified file format https://www.yinfor.com/2012/02/access_mdb_file_sorting.html https://www.yinfor.com/2012/02/access_mdb_file_sorting.html#comments Mon, 27 Feb 2012 01:26:41 +0000 https://www.yinfor.com/?p=955 When I use a ASP script to retrieve the data from a Access MDB file, I got an error: collating sequence not supported with the specified file format. Actually, it happened when I move the site to a new server....

The post How to fix the error of collating sequence not supported with the specified file format appeared first on David Yin's Blog.

]]>
When I use a ASP script to retrieve the data from a Access MDB file, I got an error: collating sequence not supported with the specified file format.
Actually, it happened when I move the site to a new server.
The solution was to go to the File tab in 2010, click the options link and set the sort order for new databases to ‘General – legacy’.

mdb-sorting-option


Then compact and repair the database file. Tools > Database Utilities > Compact and Repair Database
After above procedures, the error is gone.

The post How to fix the error of collating sequence not supported with the specified file format appeared first on David Yin's Blog.

]]>
https://www.yinfor.com/2012/02/access_mdb_file_sorting.html/feed/ 10
Solved MySQL 5 – Incorrect integer value: ” for column ‘id’ at row 1 https://www.yinfor.com/2012/02/solved_mysql_5_-_incorrect_int.html https://www.yinfor.com/2012/02/solved_mysql_5_-_incorrect_int.html#comments Tue, 21 Feb 2012 15:49:17 +0000 https://www.yinfor.com/?p=952 I move one site to a new server with Windows 2003. It is a MySQL database. I use PHP script to connect the database file and query it. I run the same script more than 5 years on the old...

The post Solved MySQL 5 – Incorrect integer value: ” for column ‘id’ at row 1 appeared first on David Yin's Blog.

]]>
I move one site to a new server with Windows 2003.
It is a MySQL database. I use PHP script to connect the database file and query it.
I run the same script more than 5 years on the old server. After I move it to new one, it gives me the error as subject.
I did a lot of Googling. Found the answer at this blog(the link is not working any more), but now it is not available. So, I quoted the most important part from the Google Cached page.

This is an sql-mode issue, the mode defines what SQL syntax should be supported and what kind of data validation should be performed. In my problem MySQL is trying to assign an empty string to an auto-increment INT field and, as we should all know, strings into INTs don’t go. Cue errors and the script dies.
Longer term I am going to have to re-work my code to fix this issue, but in the short term, I am going to reduce the sensitivity of the control. To lower the level of data validation we can set the sql-mode to a lower level or comment it out altogether.

Solution is below:
Edit the my.cnf (my.ini in windows) file and find and comment out the line:
#sql-mode=”STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION”

With this line commented out, STRICT mode is no longer applied and MySQL should now insert adjusted values for invalid or missing values and more specifically, it should allow my empty string to be put into the int column.

I follow this solution and everything is OK for MySQL installation.

The post Solved MySQL 5 – Incorrect integer value: ” for column ‘id’ at row 1 appeared first on David Yin's Blog.

]]>
https://www.yinfor.com/2012/02/solved_mysql_5_-_incorrect_int.html/feed/ 6
7z command to compress file with date as file name https://www.yinfor.com/2009/05/7z_command_to_compress_file_wi.html https://www.yinfor.com/2009/05/7z_command_to_compress_file_wi.html#comments Tue, 26 May 2009 16:53:05 +0000 https://www.yinfor.com/?p=679 It is one step of my backup script under Windows 2000. Of course it works under Windows XP. First, I use 7z as my default compress tool. Not because of it is a free, Open Source software, but it supports...

The post 7z command to compress file with date as file name appeared first on David Yin's Blog.

]]>
It is one step of my backup script under Windows 2000. Of course it works under Windows XP.
First, I use 7z as my default compress tool. Not because of it is a free, Open Source software, but it supports more format and compress methods.
The command program is 7z.exe under the installation of 7z package.
You can download it from here.


I use it in my daily backup script. So, the file name is contain date information.

7z a %DATE:~-4%-%DATE:~4,2%-%DATE:~7,2%.7z *.sql

The output file name looks like:

2009-05-26.7z

The original file is a MySQL database exporting file. So the name is *.sql.
a means add files into 7z file.
I don’t use method switch. The default is LZMA.
I give you an example. I have a database sql file about 184MB. The compressed file made by above command is 31MB. Very tiny.

The post 7z command to compress file with date as file name appeared first on David Yin's Blog.

]]>
https://www.yinfor.com/2009/05/7z_command_to_compress_file_wi.html/feed/ 1
Server Upgrade and Database moveing https://www.yinfor.com/2008/11/server_upgrade_and_database_mo.html https://www.yinfor.com/2008/11/server_upgrade_and_database_mo.html#comments Tue, 04 Nov 2008 12:42:01 +0000 https://www.yinfor.com/?p=618 Last weekend, the server which I put my Blog on, is upgraded based on the Dreamhost schedule. The new server is 64bit, and Linux is 64bit too. SO I have to rebuild my customized PHP on it, and doing a...

The post Server Upgrade and Database moveing appeared first on David Yin's Blog.

]]>
Last weekend, the server which I put my Blog on, is upgraded based on the Dreamhost schedule.
The new server is 64bit, and Linux is 64bit too.
SO I have to rebuild my customized PHP on it, and doing a lot of extension upgrade too.
Later I found I can not add new database and use the existing mysql host.
There is no option of “Use Hostname”.
I have to ask for upgrading databse too.
Today,they moved my MySQL database from alvin:ruano to my main MySQL server: lingling:myler.
Everything looks fine. If you find any strange issue, just comment here. Thank you.

The post Server Upgrade and Database moveing appeared first on David Yin's Blog.

]]>
https://www.yinfor.com/2008/11/server_upgrade_and_database_mo.html/feed/ 1
Types of Table Relationships https://www.yinfor.com/2008/04/types_of_table_relationships.html https://www.yinfor.com/2008/04/types_of_table_relationships.html#respond Mon, 14 Apr 2008 22:19:27 +0000 https://www.yinfor.com/?p=522 To create a good database, I have to know the relationship between tables. It is clear, the database I talking about is relationship database. There are three types of table relationships. One-to-one relationships One-to-many relationships Many-to-many relationships One-to-one relationships In...

The post Types of Table Relationships appeared first on David Yin's Blog.

]]>
To create a good database, I have to know the relationship between tables.
It is clear, the database I talking about is relationship database.
There are three types of table relationships.

  • One-to-one relationships
  • One-to-many relationships
  • Many-to-many relationships

One-to-one relationships
In a one-to-one relationship, a key will appear only once in a related table. It is the most simply relation.
One-to-many relationships
In a one-to-many relationship, keys from one table will appear multiple times in a related table.
The exapmle is a connection between department and employees. One department has many employees. One employee can only be in one department.
It is a very common type of relationship.


Many-to-many relationships
The many-to-many relationship often causes problems in practical examples of normalized databases, so much so that it is common to simply break many-to-many relationships into a series of one-to-many relationships.
I call it an intermediate table, which is one-to-many table. It connect the many-to-many tables.

The post Types of Table Relationships appeared first on David Yin's Blog.

]]>
https://www.yinfor.com/2008/04/types_of_table_relationships.html/feed/ 0
Main Features of MySQL https://www.yinfor.com/2008/04/main_features_of_mysql.html https://www.yinfor.com/2008/04/main_features_of_mysql.html#respond Sun, 13 Apr 2008 20:52:06 +0000 https://www.yinfor.com/?p=520 I choose MySQL as my program’s database. The main features of MySQL are: Speed Portability Ability to interface with any programming languare Price MySQL is a multithreaded server, meaning that each time a connection is made, a new server process...

The post Main Features of MySQL appeared first on David Yin's Blog.

]]>
I choose MySQL as my program’s database.
The main features of MySQL are:

  • Speed
  • Portability
  • Ability to interface with any programming languare
  • Price

MySQL is a multithreaded server, meaning that each time a connection is made, a new server process is started.
If you have to switch operating systems or languages mid-stream, use the mysqldump program to get your data out, and mysqlimport to get your data back into the system.
The ability for MySQL to interface with virtually every programming language – PHP, Perl, C/C++, Java, Python, and Tcl.
The selling point of MySQL is that it’s free, in most cases.

The post Main Features of MySQL appeared first on David Yin's Blog.

]]>
https://www.yinfor.com/2008/04/main_features_of_mysql.html/feed/ 0
PHP connect DBF file https://www.yinfor.com/2008/01/php_connect_dbf_file.html https://www.yinfor.com/2008/01/php_connect_dbf_file.html#comments Fri, 11 Jan 2008 22:42:03 +0000 https://www.yinfor.com/?p=450 DBF is very old format databse type. About 10 years ago, I use dBase which use DBF format. Now I will show you how to connect the DBF file from PHP script. 1) Add a system DSN in ODBC Data...

The post PHP connect DBF file appeared first on David Yin's Blog.

]]>
DBF is very old format databse type. About 10 years ago, I use dBase which use DBF format.
Now I will show you how to connect the DBF file from PHP script.
1) Add a system DSN in ODBC Data Source Administrator
I have a source named dd.


system_dsn

2) Make a file named odbc.php, the content is:

 <?php
 $odbc = odbc_connect ('dd', '', '') or die('Could Not Connect to ODBC Database!');
 ?>

3) In the PHP file, which needs to connect this database, I use the following script.

require_once('odbc.php');
$strsql= 'SELECT * FROM database.dbf';
$query = odbc_exec($odbc, $strsql) or die (odbc_errormsg());
while($row = odbc_fetch_array($query))
{
echo 'Client Name: '.$row['name'].'&lt;br /&gt;';
echo 'Client Phone Number: '.$row['phone'].'&lt;br /&gt;';
echo '&lt;hr /&gt;';
}
odbc_close($odbc);

Use this way, PHP can connect the old database file, like dBase, Foxpro.

The post PHP connect DBF file appeared first on David Yin's Blog.

]]>
https://www.yinfor.com/2008/01/php_connect_dbf_file.html/feed/ 32