Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8751777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:06:44+00:00 2026-06-13T13:06:44+00:00

I have two computers, one install windows 7 , another is CentOS 5.8 In

  • 0

I have two computers, one install windows 7 , another is CentOS 5.8


In CentOS…

I use yum command to install httpd(apache2.2), php5.3.3 and mysql.

  • yum install httpd
  • yum install php53
  • yum install pdo
  • yum install php53-mysql

First I check the phpinfo, the pdo, pdo_mysql is success extends,

then I also check php -m in CentOS Terminal , have extend pdo and pdo_mysql, too.

enter image description here
enter image description here


I run same code between windows 7 and CentOS

window success, but centos fail

Two files, db.php and dbtest.php

Here is db.php:

<?php

    class DB
    {
        private $conn;

        #### construct ####
        public function __construct( $dsn , $db_user , $db_password , $showError = false )
        {                       
            try
            {               
                $this->conn = new PDO( $dsn , $db_user , $db_password );

                if( $showError ) // set error information show or not. 
                {
                    $this->conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
                }
                else
                {
                    $this->conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT );
                }

                $setUtf8 = $this->conn->prepare( 'set names utf8' ); // set encoded by utf8
                $setUtf8->execute();
            }
            catch( PDOException $err )
            {
                return false;
            }
        }
    }
?>

and here is dbtest.php:

<?php

    require_once( "db.php" );

    $link_test = new DB( "mysql:dbname=pdotest;port=3306;host=192.168.1.127", "root" , "123456" );  

    var_dump($link_test);
?>

When dump in windows , the result is:

object(DB)#1 (1) { ["conn":"DB":private]=> object(PDO)#2 (0), { } }

dump in CentOS, the result is:

object(DB)#1 (1) { ["conn":"DB":private]=> NULL }

Can anyone tell me why connect fail in CentOS??


Edit at 2012/10/24 16:10 (Asia/Taipei)

For test many hour, I guess is php pdo have problem…

because in my LAN, I can connect any 3306 port mysql by CentOS Terminal

but in php pdo_mysql class, I can’t link any mysql(even CentOS local’s mysql )

so…how to check my pdo_mysql extension is operate normally?

PS: Sorry,I have poor English 🙁

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T13:06:45+00:00Added an answer on June 13, 2026 at 1:06 pm

    Waste a lot of time…finally I get the solution!!

    When I saw this question << Click link to see question

    This answer solve my problem.

    Selinux default setting is close httpd_can_network_connect and httpd_can_network_connect_db

    Just open it! PDO connection will operate normally 🙂

    Command:

    setsebool -P httpd_can_network_connect=1
    setsebool -P httpd_can_network_connect_db=1

    Thank you, Michael Berkowski

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two computers with Windows Server 2003. One computer has some shared folders
I have two computers that I use for development, one at home and one
I have one folder synced between two computers (using one of online sync tools).
I have two tables: one table (okay, it's a view), vComputer, lists many computers
I have two product to install one is server utility and other is client
I have two erlang nodes running in two different computers, in one node I
I have 3 computers. I have installed windows server + Active Directory on one
I have two pages, one sending a file_get_contents request: $postdata = http_build_query( array('install' =>
I have two computers from which I want to contribute to one github repo.
I have a program which I try to run on two computers. On one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.