php/mysql - how to see if they can connect?
am 17.10.2007 23:16:31 von Hans-Peter Sauer
I have installed php and mysql but i am not sure the 2 are able to talk to
each other.
i have created a database in mysql called test / user: test / pw: test and
given the user select privelges.
the table has one field column called test.
Can anyone tell me a simple php script to try to see if a connection can be
made and display that table column??
Re: php/mysql - how to see if they can connect?
am 18.10.2007 05:03:33 von kimandre
David wrote:
> I have installed php and mysql but i am not sure the 2 are able to
> talk to each other.
>
> i have created a database in mysql called test / user: test / pw:
> test and given the user select privelges.
>
> the table has one field column called test.
>
> Can anyone tell me a simple php script to try to see if a connection
> can be made and display that table column??
Simple sample script:
$db = mysql_connect("localhost", "test", "test");
if ($db !== false) {
echo "could not connect: ".mysql_error();
exit;
}
if (!mysql_select_db("test")) {
echo "problem selecting the database: ".mysql_error();
exit;
}
$testsel = mysql_query("SELECT * FROM `test`");
if ($testsel !== false) {
echo "it works!";
}
else {
echo "query error: ".mysql_error();
}
?>
If there's an error, it will be output to the browser (or wherever
you're running the script from). The resulting error message (if any)
might also tell you what the problem is.
--
Kim André Akerø
- kimandre@NOSPAMbetadome.com
(remove NOSPAM to contact me directly)