Jump to content

Recommended Posts

I realize this should be in the mysql forum but i need an answer quick because of the contest due tomorrow.

 

This works on my localhost but not web server.

 

On my machine: php5, apache2.0

Web server: php4.3, not sure the apache version. It's not 2.0 though.

 

Problem:

I have an SQL class. here it is (well, the beginnnig of it):\

class mysql {

function __construct() {
	$this->host = 'secret';
	$this->user = 'secret';
	$this->password = 'secret';
	$this->db = 'secret';
	$this->querycount = 0;
	$this->connect();	// call connect function below
}


// Connect and select methods
function connect() {
	$this->linkid = mysql_connect($this->host, $this->user, $this->password);
	if(!$this->linkid) {
		echo 'Could not connect to the database.';
	} 
	echo $this->linkid;
	if(! @mysql_select_db($this->db, $this->linkid) ) {
		echo 'Could not select database';
	}
}

 

now, from test.php, i do:

include('./includes/classes.php');

$sql = new mysql();

if(! $sql->connect() ) {
echo 'Not Coneected-----------';
} else {
echo 'connected!++++++++++++';
}

 

When i run the script, i get:

 

Warning: mysql_connect(): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in  path/to/includes/classes.php on line 140

Could not connect to the database.

Could not select databaseNot Coneected-----------

 

 

However, this works (Not a class):

define ('DB_USER', 'secret');
define ('DB_PASSWORD', 'secret');
define ('DB_HOST', 'secret');
define ('DB_NAME', 'secret');


$dbc = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die('ooops.. Problem:<br> '.mysql_error());
mysql_select_db (DB_NAME) OR die (mysql_error());

 

 

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/40652-solved-mysql-wont-connect/
Share on other sites

change

<?php

function __construct() {
$this->host = 'secret';
$this->user = 'secret';
$this->password = 'secret';
$this->db = 'secret';
$this->querycount = 0;
$this->connect();
// call connect function below
?>}

 

to

 

<?php

function __construct() {
var $host = 'secret';
var $user = 'secret';
var $password = 'secret';
var $db = 'secret';
var $querycount = 0;
$this->connect();
// call connect function below
}

?>

Says

change

<?php

function __construct() {
$this->host = 'secret';
$this->user = 'secret';
$this->password = 'secret';
$this->db = 'secret';
$this->querycount = 0;
$this->connect();
// call connect function below
?>}

 

to

 

<?php

function __construct() {
var $host = 'secret';
var $user = 'secret';
var $password = 'secret';
var $db = 'secret';
var $querycount = 0;
$this->connect();
// call connect function below
}

?>

 

e error: parse error, unexpected T_VAR in /path/to/includes/classes.php on line 118

 

Line 18: var $host = 'secret';

 

server's on php 4.3.

 

Just tested this. even if i do this:

class mysql {

// Connect and select methods
function connect() {
	$this->linkid = mysql_connect('secret', 'secret', 'secret');
	if(!$this->linkid) {
		echo 'Could not connect to the database.';
	} 
	echo $this->linkid;
	if(! @mysql_select_db('secret', $this->linkid) ) {
		echo 'Could not select database';
	}
}

 

It won't work. Error message:

Resource id #3

Not Coneected-----------

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.