Jump to content

mysqli problem


waynew

Recommended Posts

I've decided to start using mysqli. I've been trying to create myself a class, yet for some reason, its telling me that it cant connect to my database.

 

Warning: mysqli::mysqli() [mysqli.mysqli]: (HY000/2005): Unknown MySQL server host 'localhost:8080' (11004) in C:\Program Files\Apache Group\Apache2\htdocs\CommonCode\PHP Classes\db.class.php on line 14

 

Warning: Database::__construct() [database.--construct]: Couldn't fetch mysqli in C:\Program Files\Apache Group\Apache2\htdocs\CommonCode\PHP Classes\db.class.php on line 15

 

Warning: mysqli::query() [mysqli.query]: Couldn't fetch mysqli in C:\Program Files\Apache Group\Apache2\htdocs\CommonCode\PHP Classes\db.class.php on line 16

 

As you might imagine, I didn't get very far with this class:

 

<?php

class Database{

private $socket = "localhost:8080";
private $pass = "";
private $user = "root";
private $database = "43hsyejsm";
private $mysqli = NULL;

function __construct(){
	$mysqli = new mysqli($this->socket,$this->user,$this->pass,$this->database);
	echo $mysqli->error;
	$query = $mysqli->query("SELECT id FROM indigo_user_details LIMIT 1", MYSQLI_STORE_RESULT);

}

}

?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/131856-mysqli-problem/
Share on other sites

Try leaving of the the port number. I think you're confusing MySQL with your http server. HTTP servers (such as Apache or IIS) usually run on port 80 and sometimes port 8080. MySQL on the other hand runs on port 3306.

 

When leaving of the port PHP will by default try port 3306.

Link to comment
https://forums.phpfreaks.com/topic/131856-mysqli-problem/#findComment-685241
Share on other sites

I've personally never used mysqli_connect() (I've used the OOP one plenty of times though, except I've always used the default port), so I didn't notice the error on the link.  Sorry about any confusion. >_<  I wonder why that glitch even exists...and it's weird because http://us2.php.net/manual/en/mysqli.connect.php links to the correct function.  Why the . in between the two parts of the name instead of an underscore?  Meh.

Link to comment
https://forums.phpfreaks.com/topic/131856-mysqli-problem/#findComment-685287
Share on other sites

mysqli::__construct  ([ string $host  [, string $username  [, string $passwd  [, string $dbname  [, int $port  [, string $socket  ]]]]]] )

 

Whatever your port is, you pass it as fifth parameter, not in the first one.

 

 

 

Thanks. :) Worked. You see, my Apache is on localhost, port 80, and my MySQL is on localhost, port 8080. I had specifically set it to that.

Link to comment
https://forums.phpfreaks.com/topic/131856-mysqli-problem/#findComment-685336
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.