Just started out using MySQL and PHP with Apache 2.2 on Vista, so this may be a real 'newbee' error. I have the following PHP Code: <?PHP $username="<username>"; $password="<password>"; $database="family"; echo "Starting..... "; if(mysql_connect("127.0.0.1",$username,$password)) { @mysql_select_db("family") 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 "Table created"; } else { echo "Unable to Connect"; } ?> PHP: When executed, I receive the "Starting....." and "Unable to Connect" messages and the Apache http Server falls over. ("Appache HTTP Server stopped working and was closed") The <username> and <password> combination are correct, have full permissions on Database "family", and the Database "family" exists. The strange thing is that the Table is actually being created. (I've verified that by manually showing the columns, dropping the table, executing the php and then showing the columns.) If I use "localhost" instead of "127.0.0.1" in the connection, I get the same messages but the Apache HTTP Server doesn't fail and the Table is not created. Anyone got any ideas as to why this might be happening? Thanks
oh mysql_connect, tie that with ' or die("failed to connect because of " . mysql_error());' - do same for DB select. also check if your apache has mysql support built-in through php_info(); permissions need to be explicit for localhost or ip address - but in all likelihood, you will receive the access denied fore blah@"what you need to grant for" error on the connect. the crash of apache is quite inexplicable though...
It seems, its you web server (apache) that is the problem. How did you install it, what are you using?
Try this, see if it doesn't stop complaining: note: only change user/pass. $con = mysql_connect('localhost', 'user', 'pass'); if (!$con) { // maybe do something here. die('Sorry, the site is down for maintenance right now. Please check back later.'); } mysql_select_db("family", $con) or die('Unable to connect'); echo "Starting..... "; $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))"; $result=mysql_query($query); echo "Table created"; PHP:
Thanks for the replies. I de-installed and re-installed everything (this time following the instructions) and it's now working ok. I think it was the way I had Apache configured / installed and I missed the "Do NOT use VC9 version with apache.org binaries" warning on the PHP Download web site ! Thanks again....