View Full Version : Problem With MySQL location
JeffTPitts
7-26-06, 08:49 AM
I'm trying to start programming in PHP and I'm having a bit of trouble getting a MySQL database to work. What do I enter for the localhost?
<?
include("dbinfo.inc.php");
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "INSERT INTO contacts VALUES ('','$first','$last','$phone','$mobile','$fax','$e mail','$web')";
mysql_query($query);
mysql_close();
?>
mitchind
7-26-06, 10:24 AM
Assuming that you have already created your database in Ops Control Panel - use the server that is defined there (mysql##.powweb.com)
JeffTPitts
7-26-06, 11:57 AM
do I just enter mysql##.powweb.com or does it need to be http://www.mysql##.powweb.com ?
mitchind
7-26-06, 12:09 PM
Just like I said
Assuming that you have already created your database in Ops Control Panel - use the server that is defined there (mysql##.powweb.com)
JeffTPitts
7-26-06, 02:26 PM
Does anyone see any mistakes in this php code? It won't select the database. if I make mysql02.powweb.com http://mysql02.powweb.com or http://www.mysql02.powweb.com that error doesn't show, but it doesn't echo "Database created".
<?
$username="username";
$password="password";
$database="database";
mysql_connect(mysql02.powweb.com,$username,$passwo rd);
@mysql_select_db($database) or die( "Unable to select database");
$query="CREATE TABLE contacts (id int(6) NOT NULL auto_increment,first varchar(15) NOT NULL,last varchar(15) NOT NULL,phone varchar(20) NOT NULL,mobile varchar(20) NOT NULL,fax varchar(20) NOT NULL,email varchar(30) NOT NULL,web varchar(30) NOT NULL,PRIMARY KEY (id),UNIQUE id (id),KEY id_2 (id))";
mysql_query($query);
mysql_close();
echo "Database created";
?>
mitchind
7-26-06, 02:56 PM
Put the server in quotes ('mysql02.powweb.com') - and forget about using anything with http in it.
Check your database using phpMyAdmin thru Control Panel to make sure you can connect to it with username/password combination. See if table has already been created.
You can also die/echo mysql_error() if mysql_query() fails
It's also much easier to create your table using phpMyAdmin - especially if this is just a one time thing
JeffTPitts
7-26-06, 03:00 PM
When I set up the table just using MySQLadmin it displayed "PRIMARY and INDEX keys should not both be set for column `id`" would this cause a problem? and how can I fix in?
mitchind
7-26-06, 03:02 PM
Primary keys are automatically indexed as unique. Remove the Index key
JeffTPitts
7-26-06, 03:25 PM
I can't retrieve any information, it won't connect to the database.
<?
$user="";
$password="";
$database="db";
mysql_connect(mysql02.powweb.com,$user,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM contacts";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
echo "<b><center>Database Output</center></b><br><br>";
?>
JeffTPitts
7-26-06, 03:50 PM
I got it to work, thanks a lot for the help.
vBulletin® v3.8.7, Copyright ©2000-2013, vBulletin Solutions, Inc.