We help IT Professionals succeed at work.
Get Started

mysqli connection problem

fosiul01
fosiul01 asked
on
541 Views
Last Modified: 2012-06-21
hi
this is php 5.3.8 and mysql 5.5

both has been installed from source .

and from phpinfo.. i can see php has mysqli support. , see  bellow.

mysqli
MysqlI Support      enabled
Client API library version       5.5.17
Active Persistent Links       0
Inactive Persistent Links       0
Active Links       0
Client API header version       5.5.17
MYSQLI_SOCKET       mysqld.sock


and mysql is running as this :

 ps aux | grep mysql
root     15607  0.0  0.0  63876  1252 pts/4    S    17:08   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf
mysql    16244  0.0  2.2 4907936 364452 pts/4  Sl   17:09   0:00 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/DB/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/DB/data/posrep.err --open-files-limit=8192 --pid-file=/DB/data/posrep.pid --socket=mysqld.sock --port=3306


When i try to connect mysql from console i connect like this :
/usr/local/mysql/bin/mysql -uroot -S /DB/data/mysqld.sock -p


now problem is :
when i am trying to use mysqli wiht php .. its seems like its does not connect or it does not get any output form script.

when i execute bellow code. i get bellow error

Warning: mysqli_connect(): (HY000/2002): Can't connect to local MySQL server through socket 'mysqld.sock' (2) in /usr/local/apache/htdocs/mysql.php on line 3 Can't connect to local MySQL server through socket 'mysqld.sock' (2) Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, boolean given in /usr/local/apache/htdocs/mysql.php on line 14 Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in /usr/local/apache/htdocs/mysql.php on line 18 Warning: mysqli_close() expects parameter 1 to be mysqli, boolean given in /usr/local/apache/htdocs/mysql.php on line 33

now dont understand . where is the issue ??
can any one point me out..
is this php cant connect to mysql via mysqli  or the script has problem ??

Thanks for your help .


<?php
// Connect to database
        $link = mysqli_connect('localhost','root','xxxxx','dbname');

        // Check for Errors
        if(mysqli_connect_errno()){
          echo mysqli_connect_error();
        }

        // Prepare Query
        $query = "SELECT * FROM reportschedule r";

        // Escape Query
        $query = mysqli_real_escape_string($link,$query);


        // Perform Query
        if($result = mysqli_query($link,$query)){

         // Cycle through results
         while($row = mysqli_fetch_object($result)){
           echo $row->column;
         }


         // Free Result Set
         mysqli_free_result($result);


        }

        // Close Connection
        mysqli_close($link);
?>

Open in new window

Comment
Watch Question
CERTIFIED EXPERT
Distinguished Expert 2020
Commented:
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE