I made my attempt in PHP programming and found it very frustrating to know that my first PHP code already encountered an error.
Here's my code:
<?php
// set your infomation.
$dbhost='localhost';
$dbusername='username';
$dbuserpass='password';
$dbname='database';
// connect to the mysql database server.
mysql_connect ($dbhost, $dbusername, $dbuserpass);
//select the database
mysql_select_db($dbname) or die('Cannot select database');
//create the table, customize it if you want
$query = 'CREATE TABLE users(
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
username VARCHAR(30) NOT NULL,
password VARCHAR(20) NOT NULL,
email VARCHAR(40) NOT NULL)';
$result = mysql_query($query);
echo "Table Created!";
?>
After running the debug feature of the php software I am using, it showed this error:
PHP Fatal error: Call to undefined function mysql_connect() in C:\Program Files\Apache Group\Apache2\htdocs\samples\_debug_tmp.php on line 9
I am using Apache 2.x, MySQL 4.1.3 and PHP 5.0.2. What is wrong with my code?
Comments
Note that you must use the MySQL Improved module to connect to MySQL 4.1+. To use the older MySQL module, you have to reset your user passwords using the OLD_PASSWORD function (more info on this). But you will loose all of the interesting new features 4.1 brings if you don't use MySQLI.
Webmaster-Talk.com
Chroder.com