Solved

php mysql apache 2.2 on windows xp PLEASE Help

Posted on 2006-07-22
33
423 Views
Last Modified: 2013-12-12
Hi
i have the apache 2.2 server set up and running on my machine, i have installed latest php  and all is working fine between them, i can run scripts from my htdocs directory (localhost) and all php stuff work fine.

I have installed the latest mySQL, i have followed all the recomended config guidelines, i have my account created and i have set up a simple database through the windows cmd line window.

My problem arises when i need to use php scripts to access the database, i am new to php and mysql so this is all one big learing curve.
When i run the script from an html form it just returns the html title bit in my php script, it gives no errors but more importantly no results.

My php is installed at program files/mysql/MySQL Server 5.0/

below is my php script.

thanks

socross

<html>
<head>
  <title>Book-O-Rama Search Results</title>
</head>
<body>
<h1>Book-O-Rama Search Results</h1>
<?php
  // create short variable names
  $searchtype=$_POST['searchtype'];
  $searchterm=$_POST['searchterm'];

  $searchterm= trim($searchterm);

  if (!$searchtype || !$searchterm)
  {
     echo 'You have not entered search details.  Please go back and try again.';
     exit;
  }
 
  if (!get_magic_quotes_gpc())
  {
    $searchtype = addslashes($searchtype);
    $searchterm = addslashes($searchterm);
  }

  @ $db = new mysqli('localhost', 'bookorama', 'bookorama123', 'books');

  if (mysqli_connect_errno())
  {
     echo 'Error: Could not connect to database.  Please try again later.';
     exit;
  }

  $query = "select * from books where ".$searchtype." like '%".$searchterm."%'";
  $result = $db->query($query);

  $num_results = $result->num_rows;

  echo '<p>Number of books found: '.$num_results.'</p>';

  for ($i=0; $i <$num_results; $i++)
  {
     $row = $result->fetch_assoc();
     echo '<p><strong>'.($i+1).'. Title: ';
     echo htmlspecialchars(stripslashes($row['title']));
     echo '</strong><br />Author: ';
     echo stripslashes($row['author']);
     echo '<br />ISBN: ';
     echo stripslashes($row['isbn']);
     echo '<br />Price: ';
     echo stripslashes($row['price']);
     echo '</p>';
  }
 
  $result->free();
  $db->close();

?>
</body>
</html>
0
Comment
Question by:socross
  • 19
  • 14
33 Comments
 
LVL 8

Expert Comment

by:Yuval_Shohat
ID: 17161368
assuming everyting is working as it should,
have you tried to execute the query directly to the mysql using some GUI (phpadmin, mysql-frontmysql-query browser or just mysql...)?
i would first echo the $query to see if it exactly as i expect it to be and then try to run it using the GUI.
I suspect the problem you encounter here, is a query that has 0 results...
since you are getting no results and get no error... maybe you are getting a result that has nothing in it.

hope this helps.
-=Yuval=-
0
 
LVL 1

Author Comment

by:socross
ID: 17161803
hi
i have checked the database im querying (books) and the search im performing should definatley have results.

with regards to echo ing things i cant echo anything after the php call to open a connection to the database. it seems to ignore anything,

i am quite new to everything to do with this so apologies if i seem a little slow off the mark.

...I suspect the problem you encounter here, is a query that has 0 results...

if this is the case surely the statment

echo '<p>Number of books found: '.$num_results.'</p>';

would echo something if it got read.

thanks

if you think a gui package would be the best way to remedy this could you recommend how i got about that.
0
 
LVL 8

Expert Comment

by:Yuval_Shohat
ID: 17162678
query browser, from mysql.com:
http://dev.mysql.com/downloads/query-browser/1.1.html

-=Yuval=-
0
 
LVL 8

Expert Comment

by:Yuval_Shohat
ID: 17162689
about the code itself:

 if (mysqli_connect_errno())
  {
     echo 'Error: Could not connect to database.  Please try again later.';
     exit;
  }


from php manual:
The mysqli_connect_errno() function will return the last error code number for last call to mysqli_connect(). If no errors have occured, this function will return zero.

the function should return 0 or some error code...
just to be sure, change the if condition to something like:
if (mysqli_connect_errno()!=0)...


hope that this will help.

-=Yuval=-
0
 
LVL 8

Expert Comment

by:Yuval_Shohat
ID: 17162715
one more thing:
lets re-write:
 $result = $db->query($query);
to be a condition:

if ( $result = $db->query($query))
{echo "Query ok num_rows:".$result->num_rows;}
else
{echo "mmmm... problem with Query);}
exit;

no matter what, assuming the code got to that point, something should be echod....

-=Yuval=-
0
 
LVL 1

Author Comment

by:socross
ID: 17162769
hi
thanks for your advice but even with all that new code in place i get no errors but no echo.
If i simply echo hello; i get hello back above the call to db connection but cant below it it.

Query Browser
here are the results



SELECT * FROM books WHERE title = 'Java 2 for Professional Developers';    RETURNS A RECORD

SELECT * FROM books WHERE title LIKE 'Java 2 for Professional Developers';    RETURNS A RECORD

SELECT * FROM books where title LIKE 'Java';      RETURNS AN EMPTY RECORD


is there any problems with my sql, i thought that like would see if the word (java) matces a part of any title
thanks






0
 
LVL 8

Expert Comment

by:Yuval_Shohat
ID: 17162854
lets try something else:
go to your php.ini file search for a line that contains:
display_errors =                    
(notice there could be more than one such line in the file, but only one of these lines should start without the ; as the first character of the line).
its probably set to Off,
if so, set it to on

display_errors = On

save the file and restart the server.
try to run the script again.

o... oo.... one more thing, try to run it without the  @....

tell us how this goes.

-=Yuval=-
0
 
LVL 1

Author Comment

by:socross
ID: 17162924
hi

1. when i changed display_errors = On nothing changed (does this need changing back??)

2. When i removed the @
 i get an error

Fatal error: Class 'mysqli' not found in C:\Apache2.2\htdocs\results.php on line 27



0
 
LVL 8

Expert Comment

by:Yuval_Shohat
ID: 17163092
ok, that is a hugh clue as to what is the problem...
first read this:
from the php manual, about mysqli installation.
http://www.php.net/manual/en/ref.mysqli.php
then, some more reading:
from the mysql site, download the most updated php "driver" (extention), and some good info of how to install the extention to php.

http://dev.mysql.com/downloads/connector/php/

hope that this will do the trick.

-=Yuval=-
0
 
LVL 8

Expert Comment

by:Yuval_Shohat
ID: 17163102
and yes, change the display_errors = On  back to off
but only after solving the problem.

-=Yuval=-
0
 
LVL 1

Author Comment

by:socross
ID: 17163148
hi

i have downloaded the latest mysqle extension,

put the php_mysqli.dd into my etensions folder C:\php5\ext

and put the libmysql.dll into the folder C:\php5

as directed by the mysql site,

i have added the extention extension=php_mysqli.dll into my phpini file

my extension_dir bit =".\" and i tried it as =C:\php5\ext this made no difference so i changed it back,

i am restarting apache server inbetween all of these.

am i doing something wrong??

thanks
0
 
LVL 8

Expert Comment

by:Yuval_Shohat
ID: 17163475
mmm....
extention_dir should be
extension_dir="c:\php5\ext\"
without the "bit"...
just to make sure of it, the php_mysqli is php_mysqli.dll right? cause you wrote php_mysqli.dd... i assume this is only a typo.
make sure that c:\php5\ext is actually the path and not something else...
make sure there is no ";" at the begining of the line
try to copy libmysql.dll to windows\system32 folder (need a computer restart afterwards).
make sure you have edited the right php.ini file, usually you can find php.ini-recommanded, php.ini-dist, but there should be only one php.ini in the php core folder.
sometimes there is a php.ini file in windows\system32 folder as well....


give this a try and tell us where it got you to.

-=Yuval=-

0
 
LVL 1

Author Comment

by:socross
ID: 17163555
Hi

have checked all the bits suggested

my extension_dir now reads -------extension_dir = "c:\php5\ext\"

and  -----------extension=php_mysqli.dll

i have moved a copy of libmysql.dll to WINDOWS/system32 and after restart no difference.

I am working from php.ini but it is in my C:\WINDOWS\ directory, during installation i moved a copy or php.ini-reccommended and renamed it php.ini

thanks for your paitence

socross




0
 
LVL 8

Expert Comment

by:Yuval_Shohat
ID: 17163647
ok, another one,
lets try to put the php_mysqli.dll in the windows/system32 folder as well (with the libmysql.dll).
and in addition open the php.ini, again, make sure its the currect one, and remove the semicolon ";" from extension=php_mysql.dll
again restart the computer
then run phpinfo()
<?php
phpinfo();
?>
check to see if it says something about mysqli

thats all i can think of in regurds to the settings...


if that does not work, lets go back to the code itself,
lets start by removing the new from
$db = new mysqli('localhost', 'bookorama', 'bookorama123', 'books');

what say you?
-=Yuval=-
0
 
LVL 8

Expert Comment

by:Yuval_Shohat
ID: 17163702
next thing to check is the apache configuration file...

httpd.conf file should contain these.
LoadModule php5_module "c:/php5/php5apache2_2.dll"

as before, check that this is the correct path to the dll file.

-=Yuval=-

0
 
LVL 8

Expert Comment

by:Yuval_Shohat
ID: 17163709
depends on your apache verstion if its 2.2.x then the dll should be as i wrote in the previous msg, if its apache 2.0.x then the command should be:
LoadModule php5_module "c:/php5/php5apache2.dll"

-=Yuval=-
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Author Comment

by:socross
ID: 17163710
hi

there is no mysqli anywhere in the phpinfo window.

i di however notice that the extension_dir directory is listed as C:\php5    (not the C:\php5\ext\ that we need it to be, but i have made that change in the php.ini file)

should i have a php.ini file within my php5 directory

will try the code changes now and then get back to you
thanks
0
 
LVL 8

Expert Comment

by:Yuval_Shohat
ID: 17163729
do a search (start -> search -> all files and folders) for php.ini, check them all... i get the feeling that the php.ini file still has a wrong setting or the php.ini file is in a different folder.
check all the php.ini files you can find (dont forget to back it up).

-=Yuval=-
0
 
LVL 1

Author Comment

by:socross
ID: 17163733
i have just checked the the apache config file and all is as you say

i will try the new code now
 but i recon it has to be a config setting somewhere as the code should work, as its from a manual im learing from

thanks
0
 
LVL 1

Author Comment

by:socross
ID: 17163782
there is only one php.ini and it is in my C:\WINDOWS it is the one we have been working on

any suggestions
0
 
LVL 8

Expert Comment

by:Yuval_Shohat
ID: 17163784
here is something i found here in EE.
http://www.apachefriends.org/en/xampp-windows.html
check this tool, it supposed to be some kind of wizard which helps configure everything...
i myself dont like these kind of wizards cause they take all the fun of learning all the things that could go wrong, and yet, they usually do what they supposed to do.

any luck?

-=Yuval=-
0
 
LVL 8

Expert Comment

by:Yuval_Shohat
ID: 17163795
looking at the xampp, i can see it only supports mysql and does not say anything about mysqli which means, that it does not support it...
that could be a problem.

-=Yuval=-

0
 
LVL 8

Expert Comment

by:Yuval_Shohat
ID: 17163810
run this:


if(extension_loaded('mysqli')) {
  echo 'mysqli is loaded';
} else {
   echo 'mysqli is NOT loaded';
}

if you get not loaded, then post here the php.ini file, without your sensetive data,

-=Yuval=-
0
 
LVL 8

Expert Comment

by:Yuval_Shohat
ID: 17163821
try to take the php.ini from the windows folder and move it to the php core folder
c:\php5....

restart...

-=Yuval=-
0
 
LVL 1

Author Comment

by:socross
ID: 17163899
have moved it and no change

i am getting msqli not loaded when i run the script you gave me.

thanks

here is a link to my php.ini file

http://www.4shared.com/file/2666320/f075bbb4/php.html

0
 
LVL 8

Expert Comment

by:Yuval_Shohat
ID: 17169094
the php.ini looks fine, i checked the extension path and the extenstion of mysqli...

truthfully,  im out of ideas.
it seems that everything is just as its supposed to be and still the mysqli is not loaded...
let me sum up the main things we have tried here for anybody else who is looking  at this question, maybe it will help someone else to solve it from a fresh point of view:


the problem:
cant get mysqli to work.
error msg:
Fatal error: Class 'mysqli' not found in C:\Apache2.2\htdocs\results.php on line 27

tried to download the mysqli files from mysql.com site, followed the instructions there. => same error.

changed and  verified that php.ini is set currectly, in reguard to extension_dir (path) and extension=mysqli.dll => nothing new.
copied libmysql.dll and later added a copy of mysqli.dll to windwos\system32 folder. => failur in both cases.
checked phpinfo => no mysqli.
in order to make sure, checked extention loaded => same same no mysqli.
checked apache load module php => everything is fine with apache, and still no mysqli.


any suggestions?

-=Yuval=-
0
 
LVL 1

Author Comment

by:socross
ID: 17169595
i am completely stumped, is there any way we can broadcast this question to the mysql section see if anyone can advise.

thanks
0
 
LVL 8

Expert Comment

by:Yuval_Shohat
ID: 17169626
well, you can post the question there, with minimum points, with the title saying something like, link to a fatal error question... and in the body of the question put a link to this question.

hope someone will be able to help.

-=Yuval=-
0
 
LVL 1

Author Comment

by:socross
ID: 17174157
hi

having looked everywhere i can think of and reading through more google searchs in one day than i have in my whole life, i am completly stuck i need to get this up and running as quickly as i possibly can.

Should i start looking at starting again, if so what should i reinstall first? mysql or php or both?

How do you go about making sure you have a clean uninstall ive lost track of all the changes ive made.

thanks
0
 
LVL 1

Author Comment

by:socross
ID: 17174636
UPDATE

hi

my mysql extension is working,


as originally directed i had downloaded the latest php_mysqli.dll and replaced my one

i tried to do the same for php_mysql.dll but when i replaced it, it stoped mysql extension working ie could not see it in phpinfo.

i reverted back to my old back up of php_mysql.dll and it worked again.

this  makes me think there could be a problem with the php_mysqli.dll that i downloaded, the trouble is i dont have the original

any suggestions.









i tried to download the latest mysql connector upgrade for mysql i downloaded and then replaced the file
0
 
LVL 1

Author Comment

by:socross
ID: 17174638
-------------ignore that last line typo-------------
0
 
LVL 8

Accepted Solution

by:
Yuval_Shohat earned 500 total points
ID: 17176112
well, the original is pretty easy to find, all there is to do is to go to the php.net site and download the php installtion files and to extract only the mysql and/or the mysqli files.

-=Yuval=-
0
 
LVL 1

Author Comment

by:socross
ID: 17177616
Hi thanks for all your advice

i have literally been pulling my hair out all day, and amazingly have now solved.

when i installed php i had problems getting it to work with apache 2.2 so i upgraded to the latest snapshot of php, when i was trying to get this to work i downloaded and installed the latest connector upgrade ie (php_mysqli.dll and libmysql.dll) this is v 5.1.4.4 my new snapshot version is all 5.2.0.0 so i went back and took the php_mysqli.dll (v 5.2.0.0) from my original instalation files.

Lesson to be learnt  "must check versions im using"

Thanks ever so much

dont know which post is best to accept, its all good stuff

socross
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now