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]";
?>
NewBie! Mysql + PHP...How to ..............
Moderator: General Moderators
Q1:
Yes, using those command (and seeing results) would likely prove that mysql is working.
Q2:
$host should be 'localhost', '192.168.0.1' or whatever address pointing back at the computer running the server. Do a 'ipconfig' in a dosprompt to get the ip if localhost does not work for you.
If you have not allready, http://www.mysql.com/doc/en/Adding_users.html for more reading about adding users to your mysql userlist. Often people are running mysql as 'root'-user, but I feel it's better not to.
Hope it helps abit.
Yes, using those command (and seeing results) would likely prove that mysql is working.
Q2:
$host should be 'localhost', '192.168.0.1' or whatever address pointing back at the computer running the server. Do a 'ipconfig' in a dosprompt to get the ip if localhost does not work for you.
If you have not allready, http://www.mysql.com/doc/en/Adding_users.html for more reading about adding users to your mysql userlist. Often people are running mysql as 'root'-user, but I feel it's better not to.
Hope it helps abit.