July 7, 2007

How can I connect to mysql server?

Well ok, I should rather ask, how to connect to mysql server without using sockets. This is how I connect at this time:

  1. <?php
  2. }
  3. function connect_to_manish_db(){
  4. return $_db;
  5. Warning: mysql_connect(): Can't connect to MySQL server on 'mysql8.streamline.net' (4) in /home/fhlinux191/m/manish.sent… on line 6…
  6. function dbConnectionManish(){
  7. if(!$_dbConn){
  8. I get this error very often:
  9. I am hosting with www.streamline.net, using linux server and PHP.
  10. $pass = '';
  11. global $_db;
  12. First, I recommend using PDO to manage your connections. It is really easy to connect - $conn = new PDO ( "mysql: host=serverURL; dbname=db", $user, $pass);

    the socket issue is probably a limit on incoming connections. You can set that up through your MySQL configuration, if you use PDO you can also set it to use persistant connections which will allow you to set the max number of incoming sql connections to match the max number of children Apache can have.

    more info: http://us3.php.net/manual/en/ref.pdo.php…

  13. Heres how I do it with PHP:

    <?php
    $db=mysql_connect("localhost",…
    mysql_select_db("databasename"…

    $sql="SELECT * FROM table";
    $res=mysql_query($sql);

    ?>

    and go from there. If you want tighter security then define your connection user, pass and host and include that file or call it through a function.

  14. ?>
  15. streamline line says use tcp
  16. $_db = DB::connect($dsn, true);
  17. $user = 'root';
  18. $_dbConn = mysql_connect('localhost','roo…
  19. $host = 'localhost';
  20. $selectDB = mysql_select_db('whateverdbnam…
  21. return $_dbConn;
  22. global $_dbConn;
  23. I also tried this way :
  24. $mode = DB_FETCHMODE_ASSOC;
  25. require_once('DB.php');
  26. $db_name = 'whatevernameitis';
  27. if(!$selectDB){return false;}
  28. Full description of the error:
    Warning: mysql_connect(): Can't connect to MySQL server on 'mysql8.streamline.net' (4) in /home/fhlinux191/m/manish.sent… on line 6

    Warning: mysql_query(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/fhlinux191/m/manish.sent… on line 58

    Warning: mysql_query(): A link to the server could not be established in /home/fhlinux191/m/manish.sent… on line 58
    Query failed.Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

  29. $dsn = "mysql://$user:$pass@$host/$db…
  30. if(!$_dbConn){return false;}

Tags: ,

Tell a Friend Today!

del.icio.us Digg Furl Reddit Ask BlinkList blogmarks Blogg-Buzz Google Ma.gnolia Netscape ppnow Rojo Shadows Simpy Socializer Spurl StumbleUpon Tailrank Technorati Windows Live Wists Yahoo! Help

Permalink • Print

Track this entry

RSS BlogPulse

RSS Technorati Cosmos

Related Searches

, , , ,