You are here: Re: php/mysql - how to see if they can connect? « All PHP « IT news, forums, messages
Re: php/mysql - how to see if they can connect?

Posted by Kim Andrι Akerψ on 10/18/07 03:03

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:

<?php
$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)

 

Navigation:

[Reply to this message]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация