⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 faq.databases.html

📁 php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title>Database issues</title>  <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="faq.obtaining.html">Obtaining PHP</a></div> <div class="next" style="text-align: right; float: right;"><a href="faq.installation.html">Installation</a></div> <div class="up"><a href="faq.html">FAQ</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div>  <h1>Database issues</h1>    <p class="para">   This section holds common questions about relation between   PHP and databases. Yes, PHP can access virtually any   database available today.  </p>  <div class="qandaset"><ol class="qandaset_questions"><li><a href="#faq.databases.mssql">           I heard it&#039;s possible to access Microsoft SQL Server from PHP. How?         </a></li><li><a href="#faq.databases.access">     Can I access Microsoft Access databases?    </a></li><li><a href="#faq.databases.mysql.php5">           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      &quot;function undefined&quot; errors, what gives?         </a></li><li><a href="#faq.databases.shared-mysql">           After installing shared MySQL support, Apache dumps core as soon      as libphp4.so is loaded. Can this be fixed?         </a></li><li><a href="#faq.databases.mysqlresource">           Why do I get an error that looks something like this:      &quot;Warning: 0 is not a MySQL result index in &lt;file&gt;      on line &lt;x&gt;&quot; or &quot;Warning: Supplied argument is not      a valid MySQL result resource in &lt;file&gt; on line &lt;x&gt;&quot;?         </a></li></ol>   <dl>    <dt><strong>     <p class="para">      I heard it&#039;s possible to access Microsoft SQL Server from PHP. How?     </p>    </strong></dt>    <dd><a name="faq.databases.mssql"></a>     <p class="para">      On Windows machines, you can simply use the included ODBC support      and the correct ODBC driver.     </p>     <p class="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      <a href="http://www.php.net/extra/ctlib-linux-elf.tar.gz" class="link external">&raquo; free version of the necessary      libraries for Linux systems</a>. For other Unix operating      systems, you need to contact Sybase for the correct libraries.      Also see the answer to the next question.     </p>    </dd>   </dl>   <dl>    <dt><strong>     <p class="para">Can I access Microsoft Access databases?</p>    </strong></dt>    <dd><a name="faq.databases.access"></a>     <p class="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&#039;s ODBC drivers for Microsoft Access databases.     </p>     <p class="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.      <a href="http://www.openlinksw.com/" class="link external">&raquo; OpenLink Software</a> has Unix-based      ODBC drivers that can do this.     </p>     <p class="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 class="blockquote">       <p class="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&#039;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 <a href="http://www.openlinksw.com/" class="link external">&raquo; website</a> for a free download.       </p>      </blockquote>     </p>     <p class="para">      One option that has proved successful is to use MySQL and its      MyODBC drivers on Windows and synchronizing the databases. Steve Lawrence      writes:     </p>     <p class="para">      <ul class="itemizedlist">       <li class="listitem">        <span class="simpara">         Install MySQL on your platform according to instructions with MySQL.         Latest available from <a href="http://www.mysql.com/" class="link external">&raquo; http://www.mysql.com/</a>         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.        </span>       </li>       <li class="listitem">        <span class="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.        </span>       </li>       <li class="listitem">        <span class="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.        </span>       </li>       <li class="listitem">        <span class="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.        </span>       </li>       <li class="listitem">        <span class="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.        </span>       </li>      </ul>     </p>     <p class="para">      Tips and Tricks:      <ul class="itemizedlist">       <li class="listitem">        <span class="simpara">         You can construct your tables in Access and export them         to MySQL, then link them back in. That makes table         creation quick.        </span>       </li>       <li class="listitem">        <span class="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        </span>       </li>       <li class="listitem">        <span class="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.        </span>       </li>      </ul>     </p>    </dd>   </dl>   <dl>    <dt><strong>     <p class="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      &quot;function undefined&quot; errors, what gives?     </p>    </strong></dt>    <dd><a name="faq.databases.mysql.php5"></a>     <p class="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:     </p>     <ul class="itemizedlist">      <li class="listitem">       <p class="para">        Most systems these days already have the client library installed.       </p>      </li>      <li class="listitem">       <p class="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&#039;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.       </p>      </li>      <li class="listitem">       <p class="para">        Maintenance was somewhat lax and it was falling further and further        behind the released version.       </p>      </li>      <li class="listitem">       <p class="para">        Future versions of the library are under the GPL and thus we don&#039;t        have an upgrade path since we cannot bundle a GPL&#039;ed library in a        BSD/Apache-style licensed project.  A clean break in PHP 5 seemed        like the best option.       </p>      </li>     </ul>     <p class="para">      This won&#039;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&#039;s libmyqlclient library simply by adding the <span class="option">--with-mysql=/usr</span> option      when building PHP.  Windows users may enable the extension      <var class="filename">php_mysql.dll</var> inside <var class="filename">php.ini</var>.      For more details, see the <a href="ref.mysql.html" class="link">MySQL Reference</a>      for installation instructions. Also, be sure      <var class="filename">libmysql.dll</var> is available to the systems PATH.      For more details on how, read the FAQ on      <a href="faq.installation.html#faq.installation.addtopath" class="link">setting up the Windows      systems PATH</a>.  Because <var class="filename">libmysql.dll</var> (and      many other PHP related files) exist in the PHP folder, you&#039;ll want to      add the PHP folder to your systems PATH.     </p>    </dd>   </dl>   <dl>    <dt><strong>     <p class="para">      After installing shared MySQL support, Apache dumps core as soon      as libphp4.so is loaded. Can this be fixed?     </p>    </strong></dt>    <dd><a name="faq.databases.shared-mysql"></a>     <p class="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.     </p>    </dd>   </dl>   <dl>    <dt><strong>     <p class="para">      Why do I get an error that looks something like this:      &quot;Warning: 0 is not a MySQL result index in &lt;file&gt;      on line &lt;x&gt;&quot; or &quot;Warning: Supplied argument is not      a valid MySQL result resource in &lt;file&gt; on line &lt;x&gt;&quot;?     </p>    </strong></dt>    <dd><a name="faq.databases.mysqlresource"></a>     <p class="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:      <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br />$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysql_query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT&nbsp;*&nbsp;FROM&nbsp;tables_priv"</span><span style="color: #007700">);<br />if&nbsp;(!</span><span style="color: #0000BB">$result</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">mysql_error</span><span style="color: #007700">();<br />&nbsp;&nbsp;&nbsp;&nbsp;exit;<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>      </div>      or      <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br />$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysql_query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT&nbsp;*&nbsp;FROM&nbsp;tables_priv"</span><span style="color: #007700">)<br />&nbsp;&nbsp;&nbsp;&nbsp;or&nbsp;die(</span><span style="color: #DD0000">"Bad&nbsp;query:&nbsp;"&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">mysql_error</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>      </div>     </p>    </dd>   </dl>  </div> </div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="faq.obtaining.html">Obtaining PHP</a></div> <div class="next" style="text-align: right; float: right;"><a href="faq.installation.html">Installation</a></div> <div class="up"><a href="faq.html">FAQ</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -