waynew Posted November 8, 2008 Share Posted November 8, 2008 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 More sharing options...
waynew Posted November 8, 2008 Author Share Posted November 8, 2008 Bump. For great justice. Link to comment https://forums.phpfreaks.com/topic/131856-mysqli-problem/#findComment-684985 Share on other sites More sharing options...
waynew Posted November 8, 2008 Author Share Posted November 8, 2008 Btw, the query you see inside the constructor is only me testing. Link to comment https://forums.phpfreaks.com/topic/131856-mysqli-problem/#findComment-684989 Share on other sites More sharing options...
waynew Posted November 8, 2008 Author Share Posted November 8, 2008 Another bump. Board is fast tonight. Link to comment https://forums.phpfreaks.com/topic/131856-mysqli-problem/#findComment-685009 Share on other sites More sharing options...
waynew Posted November 8, 2008 Author Share Posted November 8, 2008 Bump now because I'm off to bed. If you're wondering, my MySQL is on localhost:8080. 100% sure of that. Link to comment https://forums.phpfreaks.com/topic/131856-mysqli-problem/#findComment-685041 Share on other sites More sharing options...
DarkWater Posted November 8, 2008 Share Posted November 8, 2008 I'd be willing to bet that MySQL is not on port 8080. 3306 is the default, and you can leave it off. Just saw your post. And you're 100% sure it's on port 8080? >_< Can you connect to it with like, phpMyAdmin or anything? Link to comment https://forums.phpfreaks.com/topic/131856-mysqli-problem/#findComment-685042 Share on other sites More sharing options...
wildteen88 Posted November 8, 2008 Share Posted November 8, 2008 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 More sharing options...
Mchl Posted November 8, 2008 Share Posted November 8, 2008 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. Link to comment https://forums.phpfreaks.com/topic/131856-mysqli-problem/#findComment-685242 Share on other sites More sharing options...
DarkWater Posted November 8, 2008 Share Posted November 8, 2008 I didn't know that, because mysqli_connect() (the non-oop one) takes a string formatted like host:port as the $host parameter (I happened to look it up instead of the constructor by accident and didn't realize it. xD) Link to comment https://forums.phpfreaks.com/topic/131856-mysqli-problem/#findComment-685262 Share on other sites More sharing options...
Mchl Posted November 8, 2008 Share Posted November 8, 2008 I didn't know that, because mysqli_connect() (the non-oop one) takes a string formatted like host:port as the $host parameter That's mysql_connect(), not even part of mysqli Link to comment https://forums.phpfreaks.com/topic/131856-mysqli-problem/#findComment-685277 Share on other sites More sharing options...
DarkWater Posted November 8, 2008 Share Posted November 8, 2008 That's SO weird. http://www.php.net/mysqli_connect links to mysql_connect(). Sorry about the confusion, I'll report that bug to php.net soon. >_< That REALLY threw me off, good catch. Link to comment https://forums.phpfreaks.com/topic/131856-mysqli-problem/#findComment-685281 Share on other sites More sharing options...
Mchl Posted November 8, 2008 Share Posted November 8, 2008 Yeah. They messed up on this url. Link to comment https://forums.phpfreaks.com/topic/131856-mysqli-problem/#findComment-685283 Share on other sites More sharing options...
DarkWater Posted November 8, 2008 Share Posted November 8, 2008 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 More sharing options...
waynew Posted November 8, 2008 Author Share Posted November 8, 2008 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 More sharing options...
Mchl Posted November 8, 2008 Share Posted November 8, 2008 Any specific reason for that? Link to comment https://forums.phpfreaks.com/topic/131856-mysqli-problem/#findComment-685371 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.