LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   zend server can't connect mysql (http://www.linuxquestions.org/questions/linux-server-73/zend-server-cant-connect-mysql-780179/)

liuguobiao 01-06-2010 01:07 AM

zend server can't connect mysql
 
Hi ,I have got a trouble in conneting mysql.

I am using slackware12.2, I have a mysql5.0.67 which system has install for me and I had install a zend server4.0.6 from http://www.zend.com/products/server/, It runs all right .When I try to run my php code in zend server(apache),it break out an error with connect to mysql.
But when I login mysql in command line ,I can see all my databases what my codes need in it.
The code was running well in windows. I try to build the zend+mysql+php environment several times in linux but never success。
how can I do to let it runs all right ? some one said I can edit php.ini, It's it right ? how can I do ?
I try my best to express my trouble, Wait for your help .

TB0ne 01-06-2010 08:57 PM

Quote:

Originally Posted by liuguobiao (Post 3815809)
Hi ,I have got a trouble in conneting mysql.

I am using slackware12.2, I have a mysql5.0.67 which system has install for me and I had install a zend server4.0.6 from http://www.zend.com/products/server/, It runs all right .When I try to run my php code in zend server(apache),it break out an error with connect to mysql.
But when I login mysql in command line ,I can see all my databases what my codes need in it.
The code was running well in windows. I try to build the zend+mysql+php environment several times in linux but never success。
how can I do to let it runs all right ? some one said I can edit php.ini, It's it right ? how can I do ?
I try my best to express my trouble, Wait for your help .

You don't post any of the code, actual error messages, or give any details, how can you expect anyone to help?

Provide details, error(s), etc., and we can try. Right now, chances are good that your code is not passing the right parameters to make the MySQL connection, or that you haven't installed the php-mysql modules.

abefroman 01-06-2010 09:11 PM

Can you connect to mysql with straight PHP (not using zend)?

liuguobiao 01-07-2010 12:10 AM

thanks for you. I didn't show the errors because the errors are too long .Here is the error:
Code:

Exception information:

Message: _connect()
#1 /usr/local/zend/share/ZendFramework/library/Zend/Db/Adapter/Abstract.php(448): Zend_Db_Adapter_Pdo_Mysql->_connect()
#2 /usr/local/zend/share/ZendFramework/library/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('DESCRIBE `divis...', Array)
#3 /usr/local/zend/share/ZendFramework/library/Zend/Db/Adapter/Pdo/Mysql.php(156): Zend_Db_Adapter_Pdo_Abstract->query('DESCRIBE `divis...')
#4 /usr/local/zend/share/ZendFramework/library/Zend/Db/Table/Abstract.php(823): Zend_Db_Adapter_Pdo_Mysql->describeTable('division', NULL)
#5 /usr/local/zend/share/ZendFramework/library/Zend/Db/Table/Abstract.php(866): Zend_Db_Table_Abstract->_setupMetadata()
#6 /usr/local/zend/share/ZendFramework/library/Zend/Db/Table/Abstract.php(973): Zend_Db_Table_Abstract->_setupPrimaryKey()
#7 /usr/local/zend/share/ZendFramework/library/Zend/Db/Table/Select.php(100): Zend_Db_Table_Abstract->info()
#8 /usr/local/zend/share/ZendFramework/library/Zend/Db/Table/Select.php(78): Zend_Db_Table_Select->setTable(Object(Default_Model_DbTable_Division))
#9 /usr/local/zend/share/ZendFramework/library/Zend/Db/Table/Abstract.php(1009): Zend_Db_Table_Select->__construct(Object(Default_Model_DbTable_Division))
#10 /usr/local/zend/share/ZendFramework/library/Zend/Db/Table/Abstract.php(1307): Zend_Db_Table_Abstract->select()
#11 /dream/workplace/server/cnadev/application/modules/default/controllers/IndexController.php(21): Zend_Db_Table_Abstract->fetchAll()
#12 /usr/local/zend/share/ZendFramework/library/Zend/Controller/Action.php(513): IndexController->indexAction()
#13 /usr/local/zend/share/ZendFramework/library/Zend/Controller/Dispatcher/Standard.php(289): Zend_Controller_Action->dispatch('indexAction')
#14 /usr/local/zend/share/ZendFramework/library/Zend/Controller/Front.php(946): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#15 /usr/local/zend/share/ZendFramework/library/Zend/Application/Bootstrap/Bootstrap.php(77): Zend_Controller_Front->dispatch()
#16 /usr/local/zend/share/ZendFramework/library/Zend/Application.php(358): Zend_Application_Bootstrap_Bootstrap->run()
#17 /dream/workplace/server/cnadev/web/index.php(29): Zend_Application->run() #18 {main}->getMessage() ?>
Stack trace:

_connect()
#1 /usr/local/zend/share/ZendFramework/library/Zend/Db/Adapter/Abstract.php(448): Zend_Db_Adapter_Pdo_Mysql->_connect()
#2 /usr/local/zend/share/ZendFramework/library/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('DESCRIBE `divis...', Array)
#3 /usr/local/zend/share/ZendFramework/library/Zend/Db/Adapter/Pdo/Mysql.php(156): Zend_Db_Adapter_Pdo_Abstract->query('DESCRIBE `divis...')
#4 /usr/local/zend/share/ZendFramework/library/Zend/Db/Table/Abstract.php(823): Zend_Db_Adapter_Pdo_Mysql->describeTable('division', NULL)
#5 /usr/local/zend/share/ZendFramework/library/Zend/Db/Table/Abstract.php(866): Zend_Db_Table_Abstract->_setupMetadata()
#6 /usr/local/zend/share/ZendFramework/library/Zend/Db/Table/Abstract.php(973): Zend_Db_Table_Abstract->_setupPrimaryKey()
#7 /usr/local/zend/share/ZendFramework/library/Zend/Db/Table/Select.php(100): Zend_Db_Table_Abstract->info()
#8 /usr/local/zend/share/ZendFramework/library/Zend/Db/Table/Select.php(78): Zend_Db_Table_Select->setTable(Object(Default_Model_DbTable_Division))
#9 /usr/local/zend/share/ZendFramework/library/Zend/Db/Table/Abstract.php(1009): Zend_Db_Table_Select->__construct(Object(Default_Model_DbTable_Division))
#10 /usr/local/zend/share/ZendFramework/library/Zend/Db/Table/Abstract.php(1307): Zend_Db_Table_Abstract->select()
#11 /dream/workplace/server/cnadev/application/modules/default/controllers/IndexController.php(21): Zend_Db_Table_Abstract->fetchAll()
#12 /usr/local/zend/share/ZendFramework/library/Zend/Controller/Action.php(513): IndexController->indexAction()
#13 /usr/local/zend/share/ZendFramework/library/Zend/Controller/Dispatcher/Standard.php(289): Zend_Controller_Action->dispatch('indexAction')
#14 /usr/local/zend/share/ZendFramework/library/Zend/Controller/Front.php(946): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#15 /usr/local/zend/share/ZendFramework/library/Zend/Application/Bootstrap/Bootstrap.php(77): Zend_Controller_Front->dispatch()
#16 /usr/local/zend/share/ZendFramework/library/Zend/Application.php(358): Zend_Application_Bootstrap_Bootstrap->run()
#17 /dream/workplace/server/cnadev/web/index.php(29): Zend_Application->run()
#18 {main}->getTraceAsString() ?>

as abefroman said ,I write a php file to connect mysql:
Code:

<?php
$link=mysql_connect('localhost','root','123456');
echo "link = ".$link;

and I found the $link is empty. So I think what TB0ne has said was right :I haven't installed the php-mysql modules. I didn't know whether it been installed or not beacause I just type './install.sh' to install zend server for linux.

If I want to install php-mysql modules in zend now what can I do ?

karnaf 01-24-2010 02:24 AM

As far as I know, MySQL extension is installed by default with Zend Server.
You can check that by logging into the Zend Server UI (probably http://localhost:10081 on your machine) and going to Server Setup | Extensions. Look for it there and see if it is on.

I assume it is loaded, otherwise you would have gotten a
Code:

Fatal error:  Call to undefined function mysql_connect() in /var/www/yourpage.php on line ...
I suggest you add some more verbosity to your code, e.g.

Code:

<?php
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', true);

$link=mysql_connect('localhost','root','123456');
if (false === $link) {
    echo mysql_error();
} else {
    echo 'link = ' . $link;
}

which may help you understand what the problem is.

May I also suggest switching to PDO? much safer and easier to handle :)

Cheers,
karnaf

liuguobiao 01-25-2010 12:45 AM

HI
karnaf I get a error with your code:
Code:

Warning: mysql_connect(): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in /dream/workplace/server/mysql.php on line 5 Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
This is a simple error ,I run command line :
Code:

sudo ln -s /var/run/mysql/mysql.sock /tmp/mysql.sock
Then it run all right with you code.
But in my code .It has error with the same Exception information I have show.
Here is my IndexController.php file ( just show important code ):
Code:

<?php
class IndexController extends Zend_Controller_Action {
        public function init() {
                /* Initialize action controller here */
        }       
        public function indexAction() {
                $division = new Default_Model_DbTable_Division ( );
 //class Default_Model_DbTable_Division is extends from
the class Zend_Db_Table_Abstract
                $type1 = $division->fetchAll ();

                echo "good";exit(1);

                $type2 = array ();
                foreach ( $type1 as $row ) {
                        $type2 [$row->divisionID] = $row->type;
                }
                $this->view->type2 = $type2;
        }
}

( Reiterate That my code were running well in windows + zend + mysql )
With my test ,I found the code stop in the line "$type1 = $division->fetchAll ();"
The line just to fetch all data from database.
I can sure ,These error are with MYSQL , But I can't found what 's wrong with it. I google it ,but few people meet this problem or some body ask but there are no people reply him ...
Trying.......and Waiting .....


All times are GMT -5. The time now is 09:37 AM.