Database driven websites page chapter4

Bail, do either of the following lines in your php.ini file

extension=php_mysql.dll
extension=php_mysqli.dll

have a ; at the start of them:

Have you tried restarting Apache?

the extension=php_mysqli.dll as the ; removed i have unistalled mysql and reinstalled it but i still gettin error in task manager it says it is runnin.if i use mysql command line
it says your mysql connection id is 1

doin me head in im nearly were i was in the book before it all broke haaa
thanks bail

any one tell me how check the ports on windows 7 incase this could be the problem?
thanks

ok i have found this fix for windows 7 but it still dont work any ideas anyone plzz im runing out

The Fix

Open up windows\system32\drivers\etc\hosts
with a text editor and comment out the line that looks like:

::1 localhostPrefix it with a #, like so:

#::1 localhostSave it and your PHP/MySQL connections will immediately begin working.
You could also use 127.0.0.1 in your connection string instead of localhost,
but I didn’t want to change code in innumerable files.

#::1 localhost

Just to get me up to date where things are at.

You have installed everything on your PC and it all works fine?

But you are still having trouble with your laptop?

On your laptop, Apache and PHP seem to be OK, but you’re having problems with MySQL?

You know your laptop is 64bit and that’s what you’re trying to install?

You can access MySQL from the command line, but PHP fails to connect?

If you go to a PHP file with

<?php
phpinfo();
?>

it shows MySQL stuff in it?

ok Mittineague this is were i am now it seems be workin ok on both comps now, but the problem i have now is when i try to connect i get this error message

Warning: mysqli_connect() [function.mysqli-connect]: [2002] A connection attempt failed because the connected party did not (trying to connect via tcp://localhost:3306) in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\connect\index.php on line 2

Warning: mysqli_connect() [function.mysqli-connect]: (HY000/2002): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\connect\index.php on line 2

Fatal error: Maximum execution time of 30 seconds exceeded in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\connect\index.php on line 2

i found this code on the net to fix the problem but it as not fixed it

The Fix

Open up windows\system32\drivers\etc\hosts
with a text editor and comment out the line that looks like:

::1 localhostPrefix it with a #, like so:

#::1 localhostSave it and your PHP/MySQL connections will immediately begin working.
You could also use 127.0.0.1 in your connection string instead of localhost,
but I didn’t want to change code in innumerable files.

#::1 localhost

so any ideas
thanks bail

I’m not familiar with the “::” syntax, but AFAIK the “#” is just commenting out that line.

But it does seem to be a Windows7 configuration bug.

You could try changing the php code to

mysql_connect("127.0.0.1", "***********", "**********") or die(mysql_error());

or try changing the hosts file’s line to

#::localhost
127.0.0.1 localhost

this is drivin me stupid

i have now got error ;

Parse error: syntax error, unexpected $end in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\connect\index.php on line 33

but the problem is in deramweaver cs4 it is only showing 32 lines so why is the error on 33 when there is nothing there??

here is the code from dwcs4

<?php

$link = mysqli_connect(!‘localhost’, ‘root’, ‘bailuk’);

if ($link)

{
$output = ‘UNABLE TO CONNECT TO DATABASE SERVER.’;
include ‘output.html.php’;
exit();
}

if (!mysqli_set_charset($link, ‘utf8’))

{
$output = ‘UNABLE TO SET DATABASE CONNECTION ENCODING.’;
include ‘output.html.php’;
exit();
}

if (!mysqli_select_db ($link, ‘ijdb’))

{
$output = ‘UNABLE TO LOCATETHE JOKE DATABASE.’;
include ‘output.html.php’;
exit();

$output = ‘DATABASE CONNECTION ESTABLISHED.’;
include ‘output.html.php’;

?>

sorry it does not show line numbers but there is only 32 lines

thanks bail

ok ive fixed the problem above it was a missing curly bracket but im back to the old error got be someone who can point me in the right direction surley you gurus have come across this before here is the error code below again
thanks (man with no hair left haa) bail

ERROR CODE:

Warning: mysqli_connect() [function.mysqli-connect]: [2002] A connection attempt failed because the connected party did not (trying to connect via tcp://localhost:3306) in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\connect\index.php on line 3

Warning: mysqli_connect() [function.mysqli-connect]: (HY000/2002): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\connect\index.php on line 3

Fatal error: Maximum execution time of 30 seconds exceeded in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\connect\index.php on line 3

ok i getting there slowly now does any one have any ideas about this code

Warning: mysqli_connect() [function.mysqli-connect]: Headers and client library minor version mismatch. Headers:50051 Library:50145 in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\connect\index.php on line 3

this is my line 3 code

$link = mysqli_connect(!‘localhost’, ‘root’, ‘bailuk’);

the unable to connect to database sever is under the error code

if i put a @ like this
$link = @mysqli_connect(!‘localhost’, ‘root’, ‘bailuk’);

the error goes away and just leaves the UNABLE TO CONNECT TO DATABASE SERVER.
any ideas plz im getting there slowly
thanks bail

I’ll say one thing, I admire your perseverance. I would have given up long ago and went with a bundled install to be able to get coding.

Be assured that many have experienced problems with installations. Unfortunately it’s a difficult thing even when it’s your own set-up let alone trying to do it remotely for someone else’s. There’s just too many possible variables in play. What is in the platform, what versions, dependencies, conflicting software, configuration settings, etc. So it’s really something everyone has to pretty much figure out on their own. One thing for certain, by the time you get through this you’ll be a step closer to being a “power user”.

First, the “@” is an error supressor it doesn’t fix an error, it keeps the error message from displaying. You should not use it when you’re debugging.

The “client library minor version mismatch” error suggests that there is a compatability issue bewteen what PHP expects and needs. You could try installing a different version of MySQL.

bail give this a try, substituting the relevant username and password for the database connection:

<?php
$apache_version            = $_SERVER['SERVER_SOFTWARE'];
$php_version            = phpversion();
$link                    = mysqli_connect("localhost", "db_user_name", "db_password");
$mysql_server_version    = mysqli_get_server_info($link);

echo "
    <p>Apache (Version: $apache_version) is running the following versions of PHP and MySQL:</br>
    PHP: $php_version</br>
    MySQL: $mysql_server_version</p>
    ";
?>

If that runs ok, then you’ll find displayed the versions in use for the web server, MySQL and PHP. It also serves as a nice test to see if PHP can connect to MySQL ok.

haa ok thanks mittineague i dont give up very easy no use in just installin the package then dont learn anythin ill keep tryin untill iget it
hello spacephoenix have have done what you said and it did what you said the only problem is i still get the error here is the error and what you said thanks

Warning: mysqli_connect() [function.mysqli-connect]: Headers and client library minor version mismatch. Headers:50051 Library:50145 in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\ est.php on line 1

Apache (Version: Apache/2.2.15 (Win32) PHP/5.2.13) is running the following versions of PHP and MySQL:
PHP: 5.2.13
MySQL: 5.1.45-community

thanks to you both for your help bail

hmm, the output of

MySQL: 5.1.45-community

confirms that a connection has been established to the MySQL server. On the computer concerned have you previosuly un-installed php and/or MySQL? Possibly you have a file lurking about from a previous installation.

yes i have i said this earlier in the forum but was told that when unistall from controll panel and removed the files from program files that it leaves i will be clear and nothing left is there any were eles left to look or just try reinstall them
thanks bail

i have unistalled everything again then i reinstalled msql but the old databases i made are stil there i have removed msql from control panel also removed the folder from c:\program files but they got to be some were eles would any one have any ideas were to look because just uninstal is still leaving files some were got to be ?

thanks bail

Did you reboot the server after the reinstall?

yes i have found loads that were left from the programs i thought it left files but there you go i have msql and apche runnin ok now just php ti go if i dont mess it up agin haa
thanks bail

i got mysql and apache workin but when i add the v6 thread safe version it stops um workin im using the one i been told in this forum but still no good any ideas

follwed the text in book aswell

thanks bail

im still getting the error for the header anyone got any ideas here is the code :

Warning: mysqli_connect() [function.mysqli-connect]: Headers and client library minor version mismatch. Headers:50051 Library:50145 in C:

how do i get um to match?

thanks bail