mysql php problem

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
sarris
Forum Contributor
Posts: 137
Joined: Mon Dec 04, 2006 2:44 pm

mysql php problem

Post by sarris »

Hi there. I just setup apache 2.0.59 and php in order to start writing php scripts.
As always tried first the echo "hallo" php and works ok.
Now i am trying to connect php and mysql. So far i have done what i think is necessary. That is:
1) set the path variable in order to show at the php intallation folder where i have all the dlls (libmysql.dd and php_mysql and php_mysql1.dd) there.
at the php.ini file
2) extension_dir = "C:\program files\php"
3) extension = php_mbstring.dll
4) extension = php_mysql.dll
5) extension = php_mysqli.dll

MySqp works perfectly as it is. I have my databases up and running and making querries and all.
I am trying to connect to mysql using
mysql_connect ("localhost","user","pass");
and nothing seems to happen. Moreover i have an echo "Hi again"; right after the mysql_connect() call and it never appears. So i guess the mysql connect() is never executed. Quite weird why i dont get the next line to be executed though.

Any ideas plz??
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Run the following in a new file and tell us the results please.

Code: Select all

<?php

$neg = array('off', 0, false, '', null);
$flags = array(
	'Register Globals' => 'register_globals',
	'Short Tags' => 'short_open_tag',
	'Display Errors' => 'display_errors',
	'Magic Quotes GPC' => 'magic_quotes_gpc',
	'Magic Quotes Runtime' => 'magic_quotes_runtime',
	'Magic Quotes Sybase' => 'magic_quotes_sybase',
);
$ve = phpversion();
$os = PHP_OS;
$er = intval(error_reporting());
foreach ($flags as $n => $v)
{
	$flags[$n] = (in_array(strtolower(ini_get($v)), $neg) ? 'Off' : 'On');
}
$cli = (php_sapi_name() == 'cli');
$eol = "\n";

$gle = get_loaded_extensions();
$rows = array();
$le = '';
$wide = 4;
$j = count($gle);
$pad = $wide - $j % $wide;
$len = max(array_map('strlen', $gle));
$func = create_function('$a', 'return str_pad($a, ' . intval($len) . ');');
$gle = array_map($func, $gle);
for($i = 0; $i < $j; $i += $wide)
{
	$le .= '   ' . implode('   ', array_slice($gle, $i, $wide)) . $eol;
}

$ec = array(
	'E_STRICT' => 2048, 'E_ALL' => 2047, 'E_USER_NOTICE' => 1024,
	'E_USER_WARNING' => 512, 'E_USER_ERROR' => 256, 'E_COMPILE_WARNING' => 128,
	'E_COMPILE_ERROR' => 64, 'E_CORE_WARNING' => 32, 'E_CORE_ERROR' => 16,
	'E_NOTICE' => 8, 'E_PARSE' => 4, 'E_WARNING' => 2, 'E_ERROR' => 1,
);

$e = array();
$t = $er;
foreach ($ec as $n => $v)
{
	if (($t & $v) == $v)
	{
		$e[] = $n;
		$t ^= $v;
	}
}
if (ceil(count($ec) / 2) + 1 < count($e))
{
	$e2 = array();
	foreach ($ec as $n => $v)
	{
		if (!in_array($n, $e) and $n != 'E_ALL')
		{
			$e2[] = $n;
		}
	}
	$er = $er . ' ((E_ALL | E_STRICT) ^ ' . implode(' ^ ', $e2) . '))';
}
else
{
	$er = $er . ' (' . implode(' | ', $e) . ')';
}

if (!$cli)
{
	echo '<html><head><title>quick info</title></head><body><pre>', $eol;
}

echo 'PHP Version: ', $ve, $eol;
echo 'PHP OS: ', $os, $eol;
echo 'Error Reporting: ', $er, $eol;
foreach ($flags as $n => $v)
{
	echo $n, ': ', $v, $eol;
}
echo 'Loaded Extensions:', $eol, $le, $eol;

if (!$cli)
{
	echo '</pre></body></html>', $eol;
}

?>
sarris
Forum Contributor
Posts: 137
Joined: Mon Dec 04, 2006 2:44 pm

Post by sarris »

These are the results of what you sent me...Thanks for the fast reply.

Code: Select all

PHP Version: 5.2.0
PHP OS: WINNT
Error Reporting: 6143 (E_ALL)
Register Globals: On
Short Tags: Off
Display Errors: Off
Magic Quotes GPC: Off
Magic Quotes Runtime: Off
Magic Quotes Sybase: Off
Loaded Extensions:
   bcmath           calendar         com_dotnet       ctype         
   session          filter           ftp              hash          
   iconv            json             odbc             pcre          
   Reflection       date             libxml           standard      
   tokenizer        zlib             SimpleXML        dom           
   SPL              wddx             xml              xmlreader     
   xmlwriter        apache2handler
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The output would suggest you don't have those modules loaded.

Are you sure you're editing the correct php.ini?

Take a look at the very beginning of the output from phpinfo() to verify which php.ini php thinks it is loaded. If the file doesn't exist, it's using defaults.
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post by dibyendrah »

If you have installed PHP using PHP installer, the default directory for php.ini is C:\windows or C:\winnt. But if you have just used the php bundle which you have extracted into C:\program files\php, then you have to rename php.ini-dist to php.ini . If php_mysql is not already loaded, just uncomment the following line from

Code: Select all

;extension=php_mysql.dll
into

Code: Select all

extension=php_mysql.dll
For the new version of php, ithese modules are already loaded. So, it's not necessary to edit the php.ini for that.
sarris
Forum Contributor
Posts: 137
Joined: Mon Dec 04, 2006 2:44 pm

Post by sarris »

php.ini path is C:\program files\php, its correct, the file is there and its the .ini that php is using according to phpinfo().

I have set that path at both the user and system enviromental variable PATH.

What else could it be? The dll's are in that path and i have set the path for extensions as C:\program files\php

Have uncommented all necessary extensions as well.

Really cant tell what might be wrong. Could it be a setting of mysql?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It may be silly and easy to miss, but did you restart Apache?
User avatar
dibyendrah
Forum Contributor
Posts: 491
Joined: Wed Oct 19, 2005 5:14 am
Location: Nepal
Contact:

Post by dibyendrah »

Your extension directory is set to

Code: Select all

extension_dir = "C:\program files\php"
Isn't that it should be set to

Code: Select all

extension_dir = "C:\program files\php\extensions"

?

If that didn't solve your problem. Just download the new installer from this URL
http://www.php.net/get/php-5.2.0-win32- ... m/a/mirror
and install it. The new version don't need to be configured to load the mysql extension as it will be loaded automatically.

Othe option is to use XAMPP which is really a great package having all the necessary things.
http://apachefriends.org
sarris
Forum Contributor
Posts: 137
Joined: Mon Dec 04, 2006 2:44 pm

Post by sarris »

hehe...well i though it restarted every time you restart your pc but it seems its not like that. I restarted it and works ok..
Thank you very much!!!
Post Reply