NewBie! Mysql + PHP...How to ..............
Posted: Sat Dec 27, 2003 10:57 am
My PHP is working well with my apache In Win2000 platform. Now I wanna check if my MySQL is working with my PHP.
To start up my MySQL server from the command prompt I type
net start mysql
Then I did the following test:
C:\bin\mysql.exe
mysql>show databases;
mysql>use library;
mysql>show tables;
mysql>describe book;
mysql>exit
bye
I am sure this information is enough to tell about what I did here to people who work with MySQL a lot.
So I have a question: Does executing these commands mean my MySQL is working properly?
If yes then how do I know what is my host, user and password to access my database? Coz without asking me for any of these info, the database straightway let me to execute the commands.
I know the following line of code will connect my php file to database. But unless I know the host and user and pass I can’t precede a single step. Please help.
<?php
$host = "localhost";
$user = "user";
$pswd = "pass";
$connect = mysql_connect($host, $user, $pswd)
or die("Could not connect: " . mysql_error());
$database = mysql_select_db('test')
or die(MySQL_Error());
$sql = "SELECT * FROM one";
$result = mysql_query($sql) or die(MySQL_Error());
$rows = mysql_fetch_row($result);
echo "$rows[0]";
?>
To start up my MySQL server from the command prompt I type
net start mysql
Then I did the following test:
C:\bin\mysql.exe
mysql>show databases;
mysql>use library;
mysql>show tables;
mysql>describe book;
mysql>exit
bye
I am sure this information is enough to tell about what I did here to people who work with MySQL a lot.
So I have a question: Does executing these commands mean my MySQL is working properly?
If yes then how do I know what is my host, user and password to access my database? Coz without asking me for any of these info, the database straightway let me to execute the commands.
I know the following line of code will connect my php file to database. But unless I know the host and user and pass I can’t precede a single step. Please help.
<?php
$host = "localhost";
$user = "user";
$pswd = "pass";
$connect = mysql_connect($host, $user, $pswd)
or die("Could not connect: " . mysql_error());
$database = mysql_select_db('test')
or die(MySQL_Error());
$sql = "SELECT * FROM one";
$result = mysql_query($sql) or die(MySQL_Error());
$rows = mysql_fetch_row($result);
echo "$rows[0]";
?>