On Tru64 5.1A, we had what looked like the mysql pthread problem, with php 5 shared lib compiling fine but crashing upon firing up apache. But, our problem turned out to be this: we were running 2 versions of mysql and attempting to use --with-mysql=/usr/local/newmysql5 to link to our running test mysql5 distribution. php was still linking against an old /usr/local/lib/mysql mysqlclient library, however (or setting up to use old /usr/local/lib/mysql shared mysqlclient.so, not sure which).
When we made sure that only /usr/local/newmysql5/lib/mysql/ mysqlclient library (which was a static one in our case) was available to our compiling user, our problem with php crashing on apache start went away. (We used tru64's handy setacl command to accomplish this.) We still have the mysql5 pthread-included compile.
This section holds common questions about relation between PHP and databases. Yes, PHP can access virtually any database available today.
- 52.1. I heard it's possible to access Microsoft SQL Server from PHP. How?
- 52.2. Can I access Microsoft Access databases?
- 52.3. I upgraded to PHP 4, and now mysql keeps telling me "Warning: MySQL: Unable to save result set in ...". What's up?
- 52.4. 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?
- 52.5. After installing shared MySQL support, Apache dumps core as soon as libphp4.so is loaded. Can this be fixed?
- 52.6. 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>"?
| 52.1. | I heard it's possible to access Microsoft SQL Server from PHP. How? |
On Windows machines, you can simply use the included ODBC support and the correct ODBC driver. 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 » free version of the necessary libraries for Linux systems. For other Unix operating systems, you need to contact Sybase for the correct libraries. Also see the answer to the next question. | |
| 52.2. | Can I access Microsoft Access databases? |
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. 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. » OpenLink Software has Unix-based ODBC drivers that can do this. 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:
One option that has proved successful is to use MySQL and its MyODBC drivers on Windows and synchronizing the databases. Steve Lawrence writes:
Tips and Tricks:
| |
| 52.3. | I upgraded to PHP 4, and now mysql keeps telling me "Warning: MySQL: Unable to save result set in ...". What's up? |
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 differing versions of those clients. Recompiling PHP 4, and adding the path to MySQL to the flag, '--with-mysql=/your/path/to/mysql' usually solves the problem. | |
| 52.4. | 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? |
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:
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 adding the --with-mysql=/usr option when building PHP. Windows users may enable the extension php_mysql.dll inside php.ini. For more details, see the MySQL Reference for installation instructions. Also, be sure libmysql.dll is available to the systems PATH. For more details on how, read the FAQ on setting up the Windows systems PATH. Because libmysql.dll (and many other PHP related files) exist in the PHP folder, you'll want to add the PHP folder to your systems PATH. | |
| 52.5. | After installing shared MySQL support, Apache dumps core as soon as libphp4.so is loaded. Can this be fixed? |
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. | |
| 52.6. | 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>"? |
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:
<?php
<?php |
Database issues
31-Aug-2006 02:48
14-Apr-2006 04:56
If Some1 is intersted on PHP with MS Access
here is some code
<?php
$db = 'C:\\Program Files\\Microsoft Office\\Office\\Samples\\Northwind.mdb';
$conn = new COM('ADODB.Connection') //or exit('Cannot start ADO.');
// Two ways to connect. Choose one.
$conn->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=$db") or exit('Cannot open with Jet.');
//$conn->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=$db") //or exit('Cannot open with driver.');
$sql = 'SELECT Table Field1,feild2...
FROM db
ORDER BY Field';
$rs = $conn->Execute($sql);
?>
Enjoy
Addis Ababa,
Ethiopia
02-Mar-2006 06:56
Building in a Redhat 4 64-bit environment:
This assumes you're using Redhat's RPMs (mysql, mysql-devel).
MySQL libraries get installed in /usr/lib64 but PHP only searches /usr/lib. This means your config will fail. You need to create a fake install of MySQL in another directory to get PHP to build correctly.
Create another directory, say /usr/local/mysql. Then cd into that directory and create 2 symbolic links pointing to the appropriate include directory and lib directory:
# mkdir /usr/local/mysql
# cd /usr/local/mysql
# ln -s /usr/include/mysql include
# ln -s /usr/lib64/mysql lib
Now, you should be able to configure PHP with "--with-mysql=/usr/local/mysql" and build properly.
01-Feb-2006 10:31
An easy way to compile PHP5 when you have installed mysql, but
- you can't find the "mysql header files" or
- get this error: Cannot find MySQL header files under /usr/
: simply install mysql-devel from mysql site.
19-Dec-2005 03:46
If one is using PHP on Windows to connection to MS SQL Server and does not want to pass credentials via the mssql_connect but instead use MS Connectionless NT Authentication, what is the proper syntax/usage?
I believe you want to turn on secure_connection in php.ini file:
; Use NT authentication when connecting to the server
mssql.secure_connection = On
08-Sep-2005 09:51
How to compile PHP5 when you have installed mysql, but
- you can't find the "mysql header files" or
- get this error: Cannot find MySQL header files under /usr/
If you want to use mysql 4.0 (*not* 4.1 or even higher!) just download & extract the latest mysql4.0 binary distribution to e.g.
/root/mysql40/
but don't start it (it even should not work, if you have a mysql server already running)
Then use --with-mysql=/root/mysql4 within your php5 configuration.
After compiling/installing (make, make install), you may delete the /root/mysql40/ directory, or keep it for later versions of php5.
Just a quick note which may help Windows users setting up PHP/Apache/MySQL. I was receiving these two error messages on Apache startup: 1) "The procedure entry point mysql_thread_end could not be located in the dynamic link library LIBMYSQL.dll" and 2) "PHP Startup: Unable to load dynamic library '<my php installation dir>/ext/php_mysql.dll' - The specified procedure could not be found". After checking that libmysql.dll did exist in my root PHP install dir, and that this dir was in my path, I determined that the problem was an older version of libmysql.dll. My solution was to search all harddrives for this file (I found 6 copies of 5 different versions), and rename all of them except my PHP install dir copy. PHP, Apache and MySQL all function as expected after making this change.
11-Oct-2004 06:53
This is a crucial piece of information for SYBASE users:
If you are using the free, but old, 11.x client libs from sybase,
then compile with option "--with-sybase-ct=$SYBASE"
substitute $SYBASE with the appropriate directory name.
option --with-sybase (without ct) can somehow be used to talk to old MS-SQL servers, but only with the 11.x client libs.
If you are using free, or have legally obtained, 12.x client libs from sybase, then compile with option "--with-sybase-ct=$SYBASE/$SYBASE_OCS"
substitute $SYBASE/$SYBASE_OCS with the appropriate directory name.
05-Nov-2003 09:38
You can connect to Microsoft SQL Server from PHP without using ODBC. It's even detailed in the PHP docs! Wow! You can find the details at http://www.php.net/manual/en/ref.mssql.php
27-Sep-2002 06:24
i made some notes of trials/tribulations setting up PHP (on a linux redhat 7.3 box) to connect (via interbase/ODBC client libraries) to an interbase server on another machine:
http://www.faqts.com/knowledge_base/view.phtml/aid/18951/fid/679
hope it helps someone..
27-Feb-2002 04:22
You can approch problem with mysql and pthread by recompiling/linking apache (1.3.2x) with pthread library instead of removing pthread from mysql. This solved my problem with apache dumping core with php (3.0.18 and php 4.1.1) and mysql.
You can use ldd to check if apache is compiled with pthreads.
Hope that helps.