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:
- <?php
- }
- function connect_to_manish_db(){
- return $_db;
- Warning: mysql_connect(): Can't connect to MySQL server on 'mysql8.streamline.net' (4) in /home/fhlinux191/m/manish.sent… on line 6…
- function dbConnectionManish(){
- if(!$_dbConn){
- I get this error very often:
- I am hosting with www.streamline.net, using linux server and PHP.
- $pass = '';
- global $_db;
- 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…
- 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.
- ?>
- streamline line says use tcp
- $_db = DB::connect($dsn, true);
- $user = 'root';
- $_dbConn = mysql_connect('localhost','roo…
- $host = 'localhost';
- $selectDB = mysql_select_db('whateverdbnam…
- return $_dbConn;
- global $_dbConn;
- I also tried this way :
- $mode = DB_FETCHMODE_ASSOC;
- require_once('DB.php');
- $db_name = 'whatevernameitis';
- if(!$selectDB){return false;}
- 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 6Warning: 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) - $dsn = "mysql://$user:$pass@$host/$db…
- if(!$_dbConn){return false;}
Tags: linux os, linux moving ubuntu























