PHP - database not selected. What is wrong with my code?
Posted
by Petr
on Stack Overflow
See other posts from Stack Overflow
or by Petr
Published on 2010-03-23T06:59:48Z
Indexed on
2010/03/23
7:03 UTC
Read the original article
Hit count: 257
Hi, I am learning PHP and tried to connect to MySQL. Altough I am using select DB, is still reports "No database selected". What is wrong, please? Thanks.
<?php
$user="test";
$pass="aaa";
ConnectToDb();
function ConnectToDb()
{
$pripojeni=mysql_connect('localhost',$user,$pass);
$selectedDB=mysql_select_db('1a');
if($query=mysql_query('select * from project'))
{
while($d=mysql_fetch_array($query))
{
echo "TEST";
}
}
else echo mysql_error($pripojeni);
}
?>
© Stack Overflow or respective owner