The problem of accessing MySQL from ZendFramework can put a
newbie to a standstill, since error messages and the absence of any drivers are far from being so clear if you haven’t really gotten into the technologies and principles used by Zend.
The benefit of the PHP language is fully documented and finding the answers is not so difficult. Despite the fact that at first glance, it would be enough just to describe the solution, I would prefer to tell you how to solve this kind of problem yourself, that is, from the moment of reading the error message to the fully working code.
Tools:- Windows XP Professional (SP2)
- ZendFramework-1.6
- PHP Version 5.2.6
- Server: StpServer 1.0
- MySQL 5.0.51b
')
After writing some code or copy-code tutorial code using the database, when I try to go to the page where some data from the database is displayed in the browser, I get an error like this:
Fatal error: Uncaught exception 'Zend_Db_Adapter_Exception' with message ' The mysql driver is not currently installed ' in T: \ home \ virtual \ zend \ library \ Zend \ Db \ Adapter \ Pdo \ Abstract.php: 103 Stack trace: # 0 T : \ home \ virtual \ zend \ library \ Zend \ Db \ Adapter \ Abstract.php (389): Zend_Db_Adapter_Pdo_Abstract -> _ connect () # 1 ...
The first thing that comes to mind is to look at the phpinfo () page in search of possible causes of the problem, which we are doing ...
There in the PDO section, it turns out that the only one of the installed PDO drivers is sqlite2. In our case, we want to use MySQL.
Note: PDO (PHP Data Objects) is an extension for the PHP language, which allows the developer to have a simple and convenient interface for accessing databases from PHP scripts.
PDO provides abstract access to databases, which means that no matter which DBMS you use, in any case you use standard PDO methods to get data and to write it to the database.
PDO is included in PHP version 5.1, and is available as an extension from PECL for PHP 5.0; PDO uses the new OO functions of the PHP 5 kernel and does not work with earlier PHP versions.
Wikipedia Free Encyclopedia
Great, now we know what a PDO is and what is actually missing. But, of course, a natural indignation arises in the address of the server assembly.
However, as reported by the official PHP site, the problem is not with the STP distribution:
If you're running a PHP 5.1 release, PDO and PDO_SQLITE is included in the distribution; it will be automatically enabled when you run configure.
It remains to find the driver for mysql.
According to the same official website, the files should be called like this:
extension = php_pdo.dll
extension = php_pdo_firebird.dll
extension = php_pdo_informix.dll
extension = php_pdo_mssql.dll
extension = php_pdo_mysql.dll
extension = php_pdo_oci.dll
extension = php_pdo_oci8.dll
extension = php_pdo_odbc.dll
extension = php_pdo_pgsql.dll
extension = php_pdo_sqlite.dll
As we learned earlier that the PDB and its drivers are written in C as part of the PECL, we just have to go to the official website of this community. We’ll have to go far, we’ll just add the pecl prefix to the PHP site address.
On
http://pecl.php.net/ we hammer the PDO keyword into the search for the Packages section.
In the search results, select the most relevant item and find ourselves on the page we need. Now click on the version number of the last stable release in the version table and search for the PDO_MYSQL link on the page that opens. Obviously we are on the right track.
However, you should not hurry and click on the link [Download Latest], it will of course give us the download of the latest release of the library, but ... in the source code. Yes, yes, this is how the PECL pages are craftily arranged.
To get to the Windows binaries, we will have to click once again on the first item in the Available Releases version table, this time 1.0.2
It is here in the description of the Package Information package that we find the cherished link:
Windows binaries can be found at http://pecl4win.php.net/ext.php/php_pdo_mysql.dll
She then we need!
After downloading a small file case, as they say, in a hat. It remains to copy it into our PHP PECL folder. In my case, this is T: \ usr \ local \ Php \ PECL \
The final touch is to add a php.ini add-on to the extensions section. to find the right place I advise you to use the search with the word pdo.
The result is such a string, among other extensions:
; extension = php_msql.dll
extension = php_mysql.dll
extension = php_mysqli.dll
; extension = php_oci8.dll
; extension = php_openssl.dll
; extension = php_oracle.dll
; extension = php_pdf.dll
extension = php_pdo.dll
extension = php_pdo_mysql.dll
; extension = php_pgsql.dll
; extension = php_printer.dll
WHAT IS IMPORTANT, you should register it after extension = php_pdo.dll, since PHP loads these modules sequentially and if the order of two lines related to PDO is confused, you will see the following message:
Warning!
PHP Startup: Unable to load dynamic library '/usr/local/PHP/PECL\php_pdo_mysql.dll' - The specified module was not found.
That's all the wisdom.
After a successful server reboot, we get a working MySQL in ZendFramework, which was what was required to achieve.
I do not think that it was so difficult, but not so simple as to sit down and guess right away. In short, who knew - do not kick, who did not - now know!