Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can !
Moderator: General Moderators
bobo12
Forum Newbie
Posts: 18 Joined: Sun Mar 04, 2007 3:48 pm
Post
by bobo12 » Sun Mar 04, 2007 3:56 pm
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I installed php, apache and mysql. The installations seem okay, but I'm unable to connect to mysql for some reason. PHP is working fine, because I can do anything that doesn't involve mysql.
The code I'm 'trying' to use is this:Code: Select all
<?php
echo "test";
$con = mysql_connect("localhost");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
else
{
echo "connected?";
}
mysql_close($con);
?>
The only thing that shows up is "test". I don't receive any kind of error message even if I turn on error messages and display errors in php.ini.
I'm using php5 with apache 2.2 and the latest version of mysql.
Is there something I'm doing wrong or a way I can fix this problem?
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Sun Mar 04, 2007 6:05 pm
try
Code: Select all
<?php
error_reporting(E_ALL);
ini_set('display_errors', true);
$me = array_filter(get_loaded_extensions(), create_function('$x', 'return false!==strpos($x, "mysql");'));
echo '<div>there are ', count($me), ' mysql-related extensions present</div>', "\n";
echo '<pre>'; var_export($me); echo "</pre>\n";
$con = mysql_connect('localhost', 'mysqlaccount', 'mysqlpassword');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
else
{
echo "connected?";
}
mysql_close($con);
?>If it tells you that php's mysql extension is not loaded take a look at the
Installation on xyz Systems sections at
http://de2.php.net/mysql
califdon
Jack of Zircons
Posts: 4484 Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA
Post
by califdon » Sun Mar 04, 2007 6:10 pm
Code: Select all
$con = mysql_connect("localhost");
You just need 2 more parameters for the mysql_connect function: user and pwd.
It should look something like:
Code: Select all
$con = mysql_connect("localhost","root","mypwd")
bobo12
Forum Newbie
Posts: 18 Joined: Sun Mar 04, 2007 3:48 pm
Post
by bobo12 » Sun Mar 04, 2007 6:40 pm
Thanks guys. I was being an idiot and didn't have everything fully setup. I tried both with and without the username and password, but without luck.
I put the libmysql.dll inside of the system32 folder and uncommented out the mysql dll in the php.ini file and it worked!
Thanks again!