doctorbill
asked on
php mysql
I have a php script which is being used to install a database on my windows server in mysql. The script creates the database and populates it. When I run the install.php file I keep getting the following error message:
Database connect failed (2005): Unknown MYSQL server host 'localhost:3307' (11004)
I have successfully installed other php / mysql databases using this exact same server name (localhost:3307) on the same server
I have also successfully used the install.php script to install the same database on another computer where Mysql is running on a default port (3306) where the address being used is only "localhost"
I have tried using an IP address and netbios name, all with the same error message
I presume it is a port issue ?
Any ideas ?
Database connect failed (2005): Unknown MYSQL server host 'localhost:3307' (11004)
I have successfully installed other php / mysql databases using this exact same server name (localhost:3307) on the same server
I have also successfully used the install.php script to install the same database on another computer where Mysql is running on a default port (3306) where the address being used is only "localhost"
I have tried using an IP address and netbios name, all with the same error message
I presume it is a port issue ?
Any ideas ?
ASKER
mysqli is being used
how do I get around this issue
how do I get around this issue
Well, if your current constructor looks like:
$mysqli = new mysqli('localhost:3307', 'user', 'password', 'db');
Then you would just change it to:
$mysqli = new mysqli('localhost', 'user', 'password', 'db', 3307);
If you're not specifying the DB name in the constructor, just pass an empty string, like:
$mysqli = new mysqli('localhost', 'user', 'password', '', 3307);
$mysqli = new mysqli('localhost:3307', 'user', 'password', 'db');
Then you would just change it to:
$mysqli = new mysqli('localhost', 'user', 'password', 'db', 3307);
If you're not specifying the DB name in the constructor, just pass an empty string, like:
$mysqli = new mysqli('localhost', 'user', 'password', '', 3307);
ASKER
would these details be in the install.php file. If so I will attach it
They might be. Code can be anywhere, so it's hard to say for sure.
ASKER
I have attached the current install file - hope it helps
install.php
install.php
At the second function before the end of the line, you have this:
function connect_db($hostname, $username, $passwd, $database = false)
{
$dbh = new mysqli($hostname, $username, $passwd);
if(mysqli_connect_errno()) {
soft_error("Database connect failed (" . mysqli_connect_errno()
. "): " . mysqli_connect_error());
}
if($database)
$dbh->select_db($database) ;
$dbh->query("SET NAMES 'utf8'");
return $dbh;
}
Just change it to:
function connect_db($hostname, $username, $passwd, $database = false, $port = 3307)
{
$dbh = new mysqli($hostname, $username, $passwd,"",$port);
if(mysqli_connect_errno()) {
soft_error("Database connect failed (" . mysqli_connect_errno()
. "): " . mysqli_connect_error());
}
if($database)
$dbh->select_db($database) ;
$dbh->query("SET NAMES 'utf8'");
return $dbh;
}
function connect_db($hostname, $username, $passwd, $database = false)
{
$dbh = new mysqli($hostname, $username, $passwd);
if(mysqli_connect_errno())
soft_error("Database connect failed (" . mysqli_connect_errno()
. "): " . mysqli_connect_error());
}
if($database)
$dbh->select_db($database)
$dbh->query("SET NAMES 'utf8'");
return $dbh;
}
Just change it to:
function connect_db($hostname, $username, $passwd, $database = false, $port = 3307)
{
$dbh = new mysqli($hostname, $username, $passwd,"",$port);
if(mysqli_connect_errno())
soft_error("Database connect failed (" . mysqli_connect_errno()
. "): " . mysqli_connect_error());
}
if($database)
$dbh->select_db($database)
$dbh->query("SET NAMES 'utf8'");
return $dbh;
}
Actually, there's probably a better way - one second.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Use that function instead. It'll let you still specify the host as "localhost:3307" and it should work a little better inside that particular application (which wasn't coded very well).
ASKER
two problems:
1. there was a checkbox on the page which allowed me to create the database
"create the database (don't check if it already exists)
This is no longer there
2. I get the following:
Software Error
Message:
Error creating events table.
No database selected
SQL query: CREATE TABLE `phpc_events` (
`eid` int(11) unsigned NOT NULL auto_increment,
`cid` int(11) unsigned NOT NULL,
`owner` int(11) unsigned NOT NULL default 0,
`subject` varchar(255) collate utf8_unicode_ci NOT NULL,
`description` text collate utf8_unicode_ci NOT NULL,
`readonly` tinyint(1) NOT NULL default 0,
`catid` int(11) unsigned default NULL,
PRIMARY KEY (`eid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
Backtrace
C:\Inetpub\wwwroot\phpcale ndar\insta ll\install .php:578 - soft_error
C:\Inetpub\wwwroot\phpcale ndar\insta ll\install .php:416 - db_error
C:\Inetpub\wwwroot\phpcale ndar\insta ll\install .php:385 - create_tables
C:\Inetpub\wwwroot\phpcale ndar\insta ll\install .php:71 - install_base
Do I need to create the database first?
1. there was a checkbox on the page which allowed me to create the database
"create the database (don't check if it already exists)
This is no longer there
2. I get the following:
Software Error
Message:
Error creating events table.
No database selected
SQL query: CREATE TABLE `phpc_events` (
`eid` int(11) unsigned NOT NULL auto_increment,
`cid` int(11) unsigned NOT NULL,
`owner` int(11) unsigned NOT NULL default 0,
`subject` varchar(255) collate utf8_unicode_ci NOT NULL,
`description` text collate utf8_unicode_ci NOT NULL,
`readonly` tinyint(1) NOT NULL default 0,
`catid` int(11) unsigned default NULL,
PRIMARY KEY (`eid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
Backtrace
C:\Inetpub\wwwroot\phpcale
C:\Inetpub\wwwroot\phpcale
C:\Inetpub\wwwroot\phpcale
C:\Inetpub\wwwroot\phpcale
Do I need to create the database first?
There's nothing in that code change that should affect the visibility of a checkbox. Are you sure you're not dealing with a different / updated script?
It looks like there should be a config file where you specify the database name as SQL_DATABASE. I would go ahead and create the database and fill in that value in the config file.
It looks like there should be a config file where you specify the database name as SQL_DATABASE. I would go ahead and create the database and fill in that value in the config file.
ASKER
I will check
Are you hosting this yourself, or are you on a webhost?
ASKER
The second code you posted worked - the database was created and it allowed me to add an admin user to it
All tables are created and correct
There is still one issue though:
when I try to access the phpcalendar index file (http://localhost/phpcalendar/index.php) I get the following issue:
Database connect failed (2005): Unknown MySQL server host "localhost:3307" (11004)
If I delete the :3307 from the config file I get:
Database connect failed (1045): Access denied for user "root@localhost" (using password: yes)
All tables are created and correct
There is still one issue though:
when I try to access the phpcalendar index file (http://localhost/phpcalendar/index.php) I get the following issue:
Database connect failed (2005): Unknown MySQL server host "localhost:3307" (11004)
If I delete the :3307 from the config file I get:
Database connect failed (1045): Access denied for user "root@localhost" (using password: yes)
There may be another section of code that you'll have to change. Search the rest of the phpcalendar code for "new mysqli" (without the quotes). Chances are that you just need to copy that same function into a different functions library.
ASKER
You are correct - I found another config file that needed changing
For your info:
The following line needed changing from:
$this->dbh = new mysqli(SQL_HOST, SQL_USER, SQL_PASSWD);
To:
$this->dbh = new mysqli(SQL_HOST, SQL_USER, SQL_PASSWD,"",3307);
Thanks very much for your help on this - without your script the database and admin user would not have been created.
All pages are working correctly
For your info:
The following line needed changing from:
$this->dbh = new mysqli(SQL_HOST, SQL_USER, SQL_PASSWD);
To:
$this->dbh = new mysqli(SQL_HOST, SQL_USER, SQL_PASSWD,"",3307);
Thanks very much for your help on this - without your script the database and admin user would not have been created.
All pages are working correctly
ASKER
Very fast and accurate response
The old mysql extension allowed the port number to be in the host name parameter after the colon.