I'm using windows xp, apache2 and mysql5.
Just finished the installation (took me one week) of php, apache and mysql.
I did my first php page trying to connect to a table in a localhost database.
The database is the same that came with mysql (test).
I created a table and populated it. Connect on it using mysql and other 3rt part database manager and I can see the data is there. But I have no clue that php did the connection properly. I put one statement (echo $total) trying to see if it did the query on the table.
Please take a look in the page and see where I am wrong.
<html>
<head>
<title> My Fist Php Page </title>
<body>
<p> <? echo "Connecting a localhost database and table"; ?> </p>
<?php
$host = "localhost";
$user = "julio";
$password = "teste";
$db = "test";
$table = "alunos";
$conn = mysql_connect($host,$user,$password) or die('Could not connect: ' . mysql_error());
$banco = mysql_select_db($db);
$sql = mysql_query("SELECT * FROM $table");
?>
<?php
$total = mysql_num_rows($sql);
?>
<? echo $total; ?></p>
</body>
</html>
I also have made a dump of the table I created too:
DBTools DBMYSQL - MySQL Database Dump
#
SET FOREIGN_KEY_CHECKS=0;
Dumping Table Structure for alunos
#
CREATE TABLE alunos (
id int(11) NOT NULL auto_increment,
aluno varchar(50) default NULL,
idade int(11) default NULL,
classe char(20) default NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
#
Dumping Data for alunos
#
INSERT INTO alunos (id, aluno, idade, classe) VALUES (1, 'João Vitor Meireles', 12, 'segunda');
INSERT INTO alunos (id, aluno, idade, classe) VALUES (2, 'Terezinha de Jesus Gonçalves', 11, 'primeira');
SET FOREIGN_KEY_CHECKS=1
Thanks a lot.
Julio Borges