I installed PHP and Mysql to run on IIS6 (only installed both, and I am unknown about the setup to get them [PHP and MYSQL] to work together) and I use the following code to create a table in EMPLOYEE in the PEOPLE database I issued from mysql client command line.
<?php
$username="root@localhost";
$password="password";
$database="people";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die("Unable to select database");
$query="CREATE TABLE EMPLOYEE (id INT(7) NOT NULL
AUTO_INCREMENT,FirstName VARCHAR(15) NOT NULL, LastName VARCHAR
(15) NOT NULL, PhoneNumbers VARCHAR(20) NOT NULL, MobileNumbers
VARCHAR(20), Position VARCHAR(30) NOT NULL, PRIMARY KEY(id))";
mysql_query($query);
mysql_close();
?>
Yet, it displays the die message. I search google for the setup of mysql and php but fail to see any corrections of php.ini offered to run the script with the database. Thank you for any help.
EDIT:
Thank you for your concerns, it works after corrected as follows,
<?php
$username="root";
$password="password";
$database="people";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die("Unable to select database");
$query="CREATE TABLE EMPLOYEE (id INT(7) NOT NULL
AUTO_INCREMENT,FirstName VARCHAR(15) NOT NULL, LastName VARCHAR
(15) NOT NULL, PhoneNumbers VARCHAR(20) NOT NULL, MobileNumbers
VARCHAR(20), Position VARCHAR(30) NOT NULL, PRIMARY KEY(id))";
mysql_query($query);
mysql_close();
?>
Instead of just saying there’s a problem, have it tell you what the problem is:
For debugging/developing, you should have an
or die(mysql_error())after EVERYmysql_*()function call.The problem is this:
That’s an unquoted string, which’ll be interpreted as an undefined constant by PHP, evaluating to a null string – so you’re trying to connection to… “nothing”.