File: databases.xml

package info (click to toggle)
php-doc 20100521-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze, wheezy
  • size: 59,992 kB
  • ctags: 4,085
  • sloc: xml: 796,833; php: 21,338; cpp: 500; sh: 117; makefile: 58; awk: 28
file content (302 lines) | stat: -rw-r--r-- 11,239 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision: 297028 $ -->
 <chapter xml:id="faq.databases" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
  <title>Database issues</title>
  <titleabbrev>Database issues</titleabbrev>

  <para>
   This section holds common questions about relation between
   PHP and databases. Yes, PHP can access virtually any
   database available today.
  </para>

  <qandaset>
   <qandaentry xml:id="faq.databases.mssql">
    <question>
     <para>
      I heard it's possible to access Microsoft SQL Server from PHP. How?
     </para>
    </question>
    <answer>
     <para>
      On Windows machines, you can simply use the included ODBC support
      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
      <link xlink:href="&url.sybase.ctlib;">free version of the necessary
      libraries for Linux systems</link>. For other Unix operating
      systems, you need to contact Sybase for the correct libraries.
      Also see the answer to the next question.
     </para>
    </answer>
   </qandaentry>

   <qandaentry xml:id="faq.databases.access">
    <question>
     <para>Can I access Microsoft Access databases?</para>
    </question>
    <answer>
     <para>
      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.
      <link xlink:href="&url.openlink;">OpenLink Software</link> has Unix-based
      ODBC drivers that can do this.
     </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:
      <blockquote>
       <para>
        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.
        Please visit our <link xlink:href="&url.openlink;">website</link> for a free download.
       </para>
      </blockquote>
     </para>
     <para>
      One option that has proved successful is to use MySQL and its
      MyODBC drivers on Windows and synchronizing the databases. Steve Lawrence
      writes:
     </para>
     <para>
      <itemizedlist>
       <listitem>
        <simpara>
         Install MySQL on your platform according to instructions with MySQL.
         Latest available from <link xlink:href="&url.mysql;">&url.mysql;</link>
         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>
       <listitem>
        <simpara>
         Download the MyODBC for Windows driver from the MySQL site.
         Install it on your Windows machine. You can test the operation with
         the utilities included with this program.
        </simpara>
       </listitem>
       <listitem>
        <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>
       <listitem>
        <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>
       <listitem>
        <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.
         Select the table to link, press OK, and presto! You can now
         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>
      </itemizedlist>
     </para>
     <para>
      Tips and Tricks:
      <itemizedlist>
       <listitem>
        <simpara>
         You can construct your tables in Access and export them
         to MySQL, then link them back in. That makes table
         creation quick.
        </simpara>
       </listitem>
       <listitem>
        <simpara>
         When creating tables in Access, you must have a primary
         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>
       <listitem>
        <simpara>
         If you change a table in MySQL, you have to re-link it
         in Access. Go to tools&gt;add-ins&gt;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
         pressing OK.
        </simpara>
       </listitem>
      </itemizedlist>
     </para>
    </answer>
   </qandaentry>

   <qandaentry xml:id="faq.databases.mysql.php5">
    <question>
     <para>
      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?
     </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>
     <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>
     <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 libmysqlclient library simply by adding the <option
      role="configure">--with-mysql=/usr</option> option
      when building PHP.  Windows users may enable the extension
      <filename>php_mysql.dll</filename> inside &php.ini;.
      For more details, see the <link linkend="ref.mysql">MySQL Reference</link>
      for installation instructions. Also, be sure
      <filename>libmysql.dll</filename> is available to the systems PATH.
      For more details on how, read the FAQ on
      <link linkend="faq.installation.addtopath">setting up the Windows
      systems PATH</link>.  Because <filename>libmysql.dll</filename> (and
      many other PHP related files) exist in the PHP folder, you'll want to
      add the PHP folder to your systems PATH.
     </para>
    </answer>
   </qandaentry>

   <qandaentry xml:id="faq.databases.shared-mysql">
    <question>
     <para>
      After installing shared MySQL support, Apache dumps core as soon
      as libphp4.so is loaded. Can this be fixed?
     </para>
    </question>
    <answer>
     <para>
      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,
      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
      fix this. Then recompile PHP with the new MySQL libs.
     </para>
    </answer>
   </qandaentry>

   <qandaentry xml: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 &lt;file&gt;
      on line &lt;x&gt;" or "Warning: Supplied argument is not
      a valid MySQL result resource in &lt;file&gt; on line &lt;x&gt;"?
     </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:
      <programlisting role="php">
<![CDATA[
<?php

$result = mysql_query("SELECT * FROM tables_priv");
if (!$result) {
    echo mysql_error();
    exit;
}
?>
]]>
      </programlisting>
      or
      <programlisting role="php">
<![CDATA[
<?php

$result = mysql_query("SELECT * FROM tables_priv")
    or die("Bad query: " . mysql_error());
?>
]]>
      </programlisting>
     </para>
    </answer>
   </qandaentry>
  </qandaset>
 </chapter>

<!-- 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
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/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
-->