2001-11-10 21:49:43 +00:00
|
|
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
2003-09-10 19:29:43 +00:00
|
|
|
<!-- $Revision: 1.21 $ -->
|
2001-07-20 18:12:03 +00:00
|
|
|
<chapter id="faq.databases">
|
2001-10-14 11:55:30 +00:00
|
|
|
<title>Database issues</title>
|
|
|
|
<titleabbrev>Database issues</titleabbrev>
|
2001-07-20 18:12:03 +00:00
|
|
|
|
2001-10-14 10:26:19 +00:00
|
|
|
<para>
|
|
|
|
This section holds common questions about relation between
|
|
|
|
PHP and databases. Yes, PHP can access virtually any
|
|
|
|
database available today.
|
|
|
|
</para>
|
2001-07-20 18:12:03 +00:00
|
|
|
|
|
|
|
<qandaset>
|
|
|
|
<qandaentry id="faq.databases.mssql">
|
|
|
|
<question>
|
|
|
|
<para>
|
|
|
|
I heard it's possible to access Microsoft SQL Server from PHP. How?
|
|
|
|
</para>
|
|
|
|
</question>
|
|
|
|
<answer>
|
|
|
|
<para>
|
2001-10-14 10:26:19 +00:00
|
|
|
On Windows machines, you can simply use the included ODBC support
|
2001-07-20 18:12:03 +00:00
|
|
|
and the correct ODBC driver.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
On Unix machines, you can use the Sybase-CT driver
|
|
|
|
to access Microsoft SQL Servers because they are (at
|
|
|
|
least mostly) protocol-compatible. Sybase has made a
|
2003-02-04 09:38:22 +00:00
|
|
|
<ulink url="&url.sybase.ctlib;">free version of the necessary
|
2001-10-14 10:26:19 +00:00
|
|
|
libraries for Linux systems</ulink>. For other Unix operating
|
|
|
|
systems, you need to contact Sybase for the correct libraries.
|
|
|
|
Also see the answer to the next question.
|
2001-07-20 18:12:03 +00:00
|
|
|
</para>
|
|
|
|
</answer>
|
|
|
|
</qandaentry>
|
|
|
|
|
|
|
|
<qandaentry id="faq.databases.access">
|
|
|
|
<question>
|
|
|
|
<para>Can I access Microsoft Access databases?</para>
|
|
|
|
</question>
|
|
|
|
<answer>
|
|
|
|
<para>
|
2001-10-14 10:26:19 +00:00
|
|
|
Yes. You already have all the tools you need if you are running
|
|
|
|
entirely under Windows 9x/Me, or NT/2000, where you can use
|
|
|
|
ODBC and Microsoft's ODBC drivers for Microsoft Access databases.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
If you are running PHP on a Unix box and want to talk to MS Access
|
|
|
|
on a Windows box you will need Unix ODBC drivers.
|
2003-02-04 09:38:22 +00:00
|
|
|
<ulink url="&url.openlink;">OpenLink Software</ulink> has Unix-based
|
2001-10-14 10:26:19 +00:00
|
|
|
ODBC drivers that can do this. There is a free pilot program where you
|
|
|
|
can download an evaluation copy that doesn't expire and prices start at
|
|
|
|
$675 for the commercial supported version.
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Another alternative is to use an SQL server that has
|
|
|
|
Windows ODBC drivers and use that to store the data, which you can
|
|
|
|
then access from Microsoft Access (using ODBC) and PHP (using the
|
|
|
|
built in drivers), or to use an intermediary file format that Access
|
|
|
|
and PHP both understand, such as flat files or dBase databases.
|
|
|
|
On this point Tim Hayes from OpenLink software writes:
|
|
|
|
<programlisting>
|
2002-03-28 00:22:32 +00:00
|
|
|
Using another database as an intermediary is not a good idea, when you can
|
|
|
|
use ODBC from PHP straight to your database - i.e. with OpenLink's drivers. If
|
|
|
|
you do need to use an intermediary file format, OpenLink have now released
|
|
|
|
Virtuoso (a virtual database engine) for NT, Linux and other unix platforms.
|
2003-02-04 09:38:22 +00:00
|
|
|
Please visit our <ulink url="&url.openlink;">website</ulink> for a free download.
|
2001-10-14 10:26:19 +00:00
|
|
|
</programlisting>
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
One option that has proven successful is to use MySQL and its
|
|
|
|
MyODBC drivers on Windows and synchronizing the databases. Steve Lawrence
|
|
|
|
writes:
|
|
|
|
</para>
|
|
|
|
<para>
|
2001-07-20 18:12:03 +00:00
|
|
|
<itemizedlist>
|
|
|
|
<listitem>
|
2001-10-14 10:26:19 +00:00
|
|
|
<simpara>
|
|
|
|
Install MySQL on your platform according to instructions with MySQL.
|
2003-02-04 09:38:22 +00:00
|
|
|
Latest available from <ulink url="&url.mysql;">www.mysql.com</ulink>
|
2001-10-14 10:26:19 +00:00
|
|
|
(get it from your mirror!). No special
|
|
|
|
configuration required except when you set up a database, and configure the
|
|
|
|
user account, you should put % in the host field, or the host name of the
|
|
|
|
Windows computer you wish to access MySQL with. Make a note of your server
|
|
|
|
name, username, and password.
|
|
|
|
</simpara>
|
|
|
|
</listitem>
|
2001-07-20 18:12:03 +00:00
|
|
|
<listitem>
|
2001-10-14 10:26:19 +00:00
|
|
|
<simpara>
|
|
|
|
Download the MyODBC for Windows driver from the MySQL site. Latest
|
|
|
|
release is myodbc-2_50_19-win95.zip (NT available too, as well as source
|
|
|
|
code). Install it on your Windows machine. You can test the operation with
|
|
|
|
the utilities included with this program.
|
|
|
|
</simpara>
|
|
|
|
</listitem>
|
2001-07-20 18:12:03 +00:00
|
|
|
<listitem>
|
2001-10-14 10:26:19 +00:00
|
|
|
<simpara>
|
|
|
|
Create a user or system dsn in your ODBC administrator, located in the
|
|
|
|
control panel. Make up a dsn name, enter your hostname, user name, password,
|
|
|
|
port, etc for you MySQL database configured in step 1.
|
|
|
|
</simpara>
|
|
|
|
</listitem>
|
2001-07-20 18:12:03 +00:00
|
|
|
<listitem>
|
2001-10-14 10:26:19 +00:00
|
|
|
<simpara>
|
|
|
|
Install Access with a full install, this makes sure you get the proper
|
|
|
|
add-ins.. at the least you will need ODBC support and the linked table
|
|
|
|
manager.
|
|
|
|
</simpara>
|
|
|
|
</listitem>
|
2001-07-20 18:12:03 +00:00
|
|
|
<listitem>
|
2001-10-14 10:26:19 +00:00
|
|
|
<simpara>
|
|
|
|
Now the fun part! Create a new access database. In the table
|
|
|
|
window right click and select Link Tables, or under the file
|
|
|
|
menu option, select Get External Data and then Link Tables.
|
|
|
|
When the file browser box comes up, select files of type: ODBC.
|
|
|
|
Select System dsn and the name of your dsn created in step 3.
|
2002-03-28 16:08:54 +00:00
|
|
|
Select the table to link, press OK, and presto! You can now
|
2001-10-14 10:26:19 +00:00
|
|
|
open the table and add/delete/edit data on your MySQL server!
|
|
|
|
You can also build queries, import/export tables to MySQL,
|
|
|
|
build forms and reports, etc.
|
|
|
|
</simpara>
|
|
|
|
</listitem>
|
2001-07-20 18:12:03 +00:00
|
|
|
</itemizedlist>
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
Tips and Tricks:
|
|
|
|
<itemizedlist>
|
|
|
|
<listitem>
|
2001-10-14 10:26:19 +00:00
|
|
|
<simpara>
|
2002-06-30 16:08:48 +00:00
|
|
|
You can construct your tables in Access and export them
|
2001-10-14 10:26:19 +00:00
|
|
|
to MySQL, then link them back in. That makes table
|
|
|
|
creation quick.
|
|
|
|
</simpara>
|
|
|
|
</listitem>
|
2001-07-20 18:12:03 +00:00
|
|
|
<listitem>
|
2001-10-14 10:26:19 +00:00
|
|
|
<simpara>
|
2002-06-30 16:08:48 +00:00
|
|
|
When creating tables in Access, you must have a primary
|
2001-10-14 10:26:19 +00:00
|
|
|
key defined in order to have write access to the table in
|
|
|
|
access. Make sure you create a primary key in MySQL before
|
|
|
|
linking in access
|
|
|
|
</simpara>
|
|
|
|
</listitem>
|
2001-07-20 18:12:03 +00:00
|
|
|
<listitem>
|
2001-10-14 10:26:19 +00:00
|
|
|
<simpara>
|
|
|
|
If you change a table in MySQL, you have to re-link it
|
|
|
|
in Access. Go to tools>add-ins>linked table manager,
|
|
|
|
cruise to your ODBC DSN, and select the table to re-link
|
|
|
|
from there. you can also move your dsn source around there,
|
|
|
|
just hit the always prompt for new location checkbox before
|
2002-03-28 16:08:54 +00:00
|
|
|
pressing OK.
|
2001-10-14 10:26:19 +00:00
|
|
|
</simpara>
|
|
|
|
</listitem>
|
2001-07-20 18:12:03 +00:00
|
|
|
</itemizedlist>
|
|
|
|
</para>
|
|
|
|
</answer>
|
|
|
|
</qandaentry>
|
|
|
|
|
2001-10-14 10:26:19 +00:00
|
|
|
<qandaentry id="faq.databases.upgraded">
|
2001-07-20 18:12:03 +00:00
|
|
|
<question>
|
|
|
|
<para>
|
2001-10-14 10:26:19 +00:00
|
|
|
I upgraded to PHP 4, and now mysql keeps telling me
|
|
|
|
"Warning: MySQL: Unable to save result set in ...". What's up?
|
2001-07-20 18:12:03 +00:00
|
|
|
</para>
|
|
|
|
</question>
|
|
|
|
<answer>
|
|
|
|
<para>
|
2001-10-14 10:26:19 +00:00
|
|
|
Most likely what has happened is, PHP 4 was compiled with the '--with-mysql'
|
|
|
|
option, without specifying the path to MySQL. This means PHP is using its
|
|
|
|
built-in MySQL client library. If your system is running applications,
|
|
|
|
such as PHP 3 as a concurrent Apache module, or auth-mysql, that use other
|
|
|
|
versions of MySQL clients, then there is a conflict between the two
|
2001-07-20 18:12:03 +00:00
|
|
|
differing versions of those clients.
|
|
|
|
</para>
|
|
|
|
<para>
|
2001-10-14 10:26:19 +00:00
|
|
|
Recompiling PHP 4, and adding the path to MySQL to the flag,
|
2003-05-01 02:59:08 +00:00
|
|
|
'<link linkend="mysql.configure">--with-mysql=/your/path/to/mysql</link>'
|
2001-07-20 18:12:03 +00:00
|
|
|
usually solves the problem.
|
|
|
|
</para>
|
|
|
|
</answer>
|
|
|
|
</qandaentry>
|
|
|
|
|
2003-07-02 06:51:23 +00:00
|
|
|
<qandaentry id="faq.databases.mysql.php5">
|
|
|
|
<question>
|
|
|
|
<para>
|
2003-09-10 19:29:43 +00:00
|
|
|
PHP 5 no longer bundles MySQL client libraries, what does this mean to
|
|
|
|
me? Can I still use MySQL with PHP? I try to use MySQL and get
|
|
|
|
"function undefined" errors, what gives?
|
2003-07-02 06:51:23 +00:00
|
|
|
</para>
|
|
|
|
</question>
|
|
|
|
<answer>
|
|
|
|
<para>
|
|
|
|
Yes. There will always be MySQL support in PHP of one kind or
|
|
|
|
another. The only change in PHP 5 is that we are no longer bundling
|
|
|
|
the client library itself. Some reasons in no particular order:
|
|
|
|
</para>
|
2003-07-02 17:30:48 +00:00
|
|
|
<itemizedlist>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Most systems these days already have the client library installed.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Given the above, having multiple versions of the library can get
|
|
|
|
messy. For example, if you link mod_auth_mysql against one version
|
|
|
|
and PHP against another, and then enable both in Apache, you get a
|
|
|
|
nice fat crash. Also, the bundled library didn't always play well
|
|
|
|
with the installed server version. The most obvious symptom of this
|
|
|
|
being disagreement over where to find the mysql.socket unix domain
|
|
|
|
socket file.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Maintenance was somewhat lax and it was falling further and further
|
|
|
|
behind the released version.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Future versions of the library are under the GPL and thus we don't
|
|
|
|
have an upgrade path since we cannot bundle a GPL'ed library in a
|
|
|
|
BSD/Apache-style licensed project. A clean break in PHP 5 seemed
|
|
|
|
like the best option.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</itemizedlist>
|
2003-07-02 06:51:23 +00:00
|
|
|
<para>
|
|
|
|
This won't actually affect that many people. UNIX users, at least the
|
|
|
|
ones who know what they are doing, tend to always build PHP against
|
|
|
|
their system's libmyqlclient library simply by doing --with-mysql=/usr
|
|
|
|
when building PHP. Windows users may enable the extension
|
|
|
|
<filename>php_mysql.dll</filename> inside &php.ini;. Also, copy
|
|
|
|
<filename>libmySQL.dll</filename> into the appropriate
|
|
|
|
<literal>%SYSTEMROOT%</literal> directory, just like you do with every
|
|
|
|
other bundled DLL from the <filename>dll</filename> directory.
|
|
|
|
</para>
|
|
|
|
</answer>
|
|
|
|
</qandaentry>
|
|
|
|
|
2001-09-30 18:36:39 +00:00
|
|
|
<qandaentry id="faq.databases.shared-mysql">
|
2001-07-20 18:12:03 +00:00
|
|
|
<question>
|
|
|
|
<para>
|
2001-10-14 10:26:19 +00:00
|
|
|
After installing shared MySQL support, Apache dumps core as soon
|
2001-07-20 18:12:03 +00:00
|
|
|
as libphp4.so is loaded. Can this be fixed?
|
|
|
|
</para>
|
|
|
|
</question>
|
|
|
|
<answer>
|
|
|
|
<para>
|
2001-10-14 10:26:19 +00:00
|
|
|
If your MySQL libs are linked against pthreads this will happen. Check
|
|
|
|
using ldd. If they are, grab the MySQL tarball and compile from source,
|
2001-07-20 18:12:03 +00:00
|
|
|
or recompile from the source rpm and remove the switch in the spec file
|
|
|
|
that turns on the threaded client code. Either of these suggestions will
|
2001-10-14 10:26:19 +00:00
|
|
|
fix this. Then recompile PHP with the new MySQL libs.
|
2001-07-20 18:12:03 +00:00
|
|
|
</para>
|
|
|
|
</answer>
|
|
|
|
</qandaentry>
|
2001-10-14 11:55:30 +00:00
|
|
|
|
|
|
|
<qandaentry id="faq.databases.mysqlresource">
|
|
|
|
<question>
|
|
|
|
<para>
|
|
|
|
Why do I get an error that looks something like this:
|
|
|
|
"Warning: 0 is not a MySQL result index in <file>
|
|
|
|
on line <x>" or "Warning: Supplied argument is not
|
|
|
|
a valid MySQL result resource in <file> on line <x>?
|
|
|
|
</para>
|
|
|
|
</question>
|
|
|
|
<answer>
|
|
|
|
<para>
|
|
|
|
You are trying to use a result identifier that is 0. The 0 indicates
|
|
|
|
that your query failed for some reason. You need to check for errors
|
|
|
|
after submitting a query and before you attempt to use the returned
|
|
|
|
result identifier. The proper way to do this is with code similar
|
|
|
|
to the following:
|
2001-11-09 15:48:16 +00:00
|
|
|
<programlisting role="php">
|
2001-10-14 11:55:30 +00:00
|
|
|
$result = mysql_query("SELECT * FROM tables_priv");
|
|
|
|
if (!$result) {
|
|
|
|
echo mysql_error();
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
</programlisting>
|
|
|
|
or
|
2001-11-09 15:48:16 +00:00
|
|
|
<programlisting role="php">
|
2001-10-14 11:55:30 +00:00
|
|
|
$result = mysql_query("SELECT * FROM tables_priv")
|
|
|
|
or die("Bad query: ".mysql_error());
|
|
|
|
</programlisting>
|
|
|
|
</para>
|
|
|
|
</answer>
|
|
|
|
</qandaentry>
|
2001-07-20 18:12:03 +00:00
|
|
|
</qandaset>
|
|
|
|
</chapter>
|
|
|
|
|
2001-09-21 22:47:49 +00:00
|
|
|
<!-- Keep this comment at the end of the file
|
|
|
|
Local variables:
|
|
|
|
mode: sgml
|
|
|
|
sgml-omittag:t
|
|
|
|
sgml-shorttag:t
|
|
|
|
sgml-minimize-attributes:nil
|
|
|
|
sgml-always-quote-attributes:t
|
|
|
|
sgml-indent-step:1
|
|
|
|
sgml-indent-data:t
|
2001-12-12 20:47:43 +00:00
|
|
|
indent-tabs-mode:nil
|
2001-09-21 22:47:49 +00:00
|
|
|
sgml-parent-document:nil
|
|
|
|
sgml-default-dtd-file:"../../manual.ced"
|
|
|
|
sgml-exposed-tags:nil
|
|
|
|
sgml-local-catalogs:nil
|
|
|
|
sgml-local-ecat-files:nil
|
|
|
|
End:
|
|
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
|
|
vim: et tw=78 syn=sgml
|
|
|
|
vi: ts=1 sw=1
|
|
|
|
-->
|