Jump to content

[SOLVED] PHP Apache and MYSQL


Testing the connection between PHP and MYsql  

  1. 1. Testing the connection between PHP and MYsql

    • Testing the connection between PHP and MYsql
      0
    • Testing the connection between PHP and MYsql
      0


Recommended Posts

I am new to PHP.

I'm using a windows os and have already installed Apache, Mysql and php. I have tested a php file and it works, the apache server is running.

But i cannot get the connection between PHP and Mysql to work.

I am using the following .php file to test it:

"<html>
<head><title>Test MySQL</title></head>
<body>
<!-- mysql_up.php -->
<?php
mysqli_connect("localhost", "root", "password") or die(mysql_error());
echo "Connected to MySQL<br />";
?>

</body>
</html>
"

where i changed the word password by my password.

It does not give me an error but it doesn't give me the"Connected to MySQL" message either...just a blank page.

Can someone help me with this please. I have been stuck on this for some time now.

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/30850-solved-php-apache-and-mysql/
Share on other sites

Look in your servers error logs file and see if there are any errors being logged, also I'd recommend you to turn on the display_errors in the php.ini - make sure you restart the server when do change this setting.

When you tun on display_errors it will display the errors in your script on your screen.


If you get any errors please post them here in full.
Thank you for replying.

I do not have any servers error logs file.

I changed the display_errors to on but still do no get any errors.

To be honest I am not sure if i followed the correct steps installing and configuring php and php.ini in the first place.

This is what I did:

---created a new folder in c:
---extracted php-5.2.0-Win32.zip
---copied php.ini-dist to c:Windows and renamed it php.ini
php.ini COnfiguration:
---took out the semicolon from - extension=php_mysql.dll
---added extension=php_mysqli.dll



Thanks

When you enabled display errors did you restart the server? Also Apache by default should have an error log setup - it is located in the logs folder within the Apache installation folder.

Try copying a file called libmysql.dll  (located in the root of the PHP folder) to C:/Windows too. the mysql extension requires this file in order to function.

When ever you move files/modify configuration files the server must be restarted for the changes to be made.
Hi,

Yes i started the server after enabling display errors. And i think i found error log(look further down).

I copied the file 'libmysql.dll' to c:Windows. 

Haven't gotten to work yet.

[Sun Dec 17 20:36:20 2006] [notice] Parent: Received restart signal -- Restarting the server.
[Sun Dec 17 20:36:20 2006] [notice] Child 1444: Exit event signaled. Child process is ending.
[Sun Dec 17 20:36:20 2006] [notice] Apache/2.2.3 (Win32) configured -- resuming normal operations
[Sun Dec 17 20:36:20 2006] [notice] Server built: Jul 27 2006 16:49:49
[Sun Dec 17 20:36:20 2006] [notice] Parent: Created child process 3332
[Sun Dec 17 20:36:20 2006] [notice] Child 3332: Child process is running
[Sun Dec 17 20:36:21 2006] [notice] Child 1444: Released the start mutex
[Sun Dec 17 20:36:21 2006] [notice] Child 3332: Acquired the start mutex.
[Sun Dec 17 20:36:21 2006] [notice] Child 3332: Starting 250 worker threads.
[Sun Dec 17 20:36:22 2006] [notice] Child 1444: Waiting for 250 worker threads to exit.
[Sun Dec 17 20:36:22 2006] [notice] Child 3332: Starting thread to listen on port 80.
[Sun Dec 17 20:36:25 2006] [notice] Child 1444: All worker threads have exited.
[Sun Dec 17 20:36:25 2006] [notice] Child 1444: Child process is exiting
[Sun Dec 17 20:39:49 2006] [notice] Parent: Received restart signal -- Restarting the server.
[Sun Dec 17 20:39:49 2006] [notice] Child 3332: Exit event signaled. Child process is ending.
[Sun Dec 17 20:39:49 2006] [notice] Apache/2.2.3 (Win32) configured -- resuming normal operations
[Sun Dec 17 20:39:49 2006] [notice] Server built: Jul 27 2006 16:49:49
[Sun Dec 17 20:39:49 2006] [notice] Parent: Created child process 1932
[Sun Dec 17 20:39:49 2006] [notice] Child 1932: Child process is running
[Sun Dec 17 20:39:50 2006] [notice] Child 1932: Acquired the start mutex.
[Sun Dec 17 20:39:50 2006] [notice] Child 1932: Starting 250 worker threads.
[Sun Dec 17 20:39:50 2006] [notice] Child 3332: Released the start mutex
[Sun Dec 17 20:39:51 2006] [notice] Child 3332: Waiting for 250 worker threads to exit.
[Sun Dec 17 20:39:51 2006] [notice] Child 3332: All worker threads have exited.
[Sun Dec 17 20:39:51 2006] [notice] Child 3332: Child process is exiting
[Sun Dec 17 20:39:51 2006] [notice] Child 1932: Starting thread to listen on port 80.
[Sun Dec 17 20:39:57 2006] [notice] Parent: Received restart signal -- Restarting the server.
[Sun Dec 17 20:39:57 2006] [notice] Child 1932: Exit event signaled. Child process is ending.
[Sun Dec 17 20:39:57 2006] [notice] Apache/2.2.3 (Win32) configured -- resuming normal operations
[Sun Dec 17 20:39:57 2006] [notice] Server built: Jul 27 2006 16:49:49
[Sun Dec 17 20:39:57 2006] [notice] Parent: Created child process 2844
[Sun Dec 17 20:39:57 2006] [notice] Child 2844: Child process is running
[Sun Dec 17 20:39:58 2006] [notice] Child 1932: Released the start mutex
[Sun Dec 17 20:39:58 2006] [notice] Child 2844: Acquired the start mutex.
[Sun Dec 17 20:39:58 2006] [notice] Child 2844: Starting 250 worker threads.
[Sun Dec 17 20:39:59 2006] [notice] Child 1932: Waiting for 250 worker threads to exit.
[Sun Dec 17 20:39:59 2006] [notice] Child 1932: All worker threads have exited.
[Sun Dec 17 20:39:59 2006] [notice] Child 1932: Child process is exiting
[Sun Dec 17 20:39:59 2006] [notice] Child 2844: Starting thread to listen on port 80.
Hi...thanks for you help...I think we made some progress...Just a little more...I hope:)

I have php.in and libmysql.dll in c:windows

The php.ini has:

display_errors = on

doc_root = C:\Program Files\Apache Software Foundation\Apache2.2\htdocs

extension_dir = C:\php\ext

extension=php_mysql.dll
extension=php_mysqli.dll

I am now getting the error:

"Fatal error: Call to undefined function mysqli_connect() in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\mysql_up.php on line 12
"

When using the following file(Where it says password, i put my password):

<html>
<head><title>Test MySQL</title></head>
<body>
<!-- mysql_up.php -->
<?php
error_reporting(E_ALL);

$host="localhost";
$user="root";
$password="password";

$connect = mysqli_connect($host,$user,$password);
$sql="show status";
$result = mysqli_query($connect,$sql);
if ($result == false)
echo "<b>Error " . mysqli_errno() . ": "
        . mysqli_error() . "</b>";
else
{
?>
<!-- Table that displays the results -->
<table border=”1”>
<tr><td><b>Variable_name</b></td>
<td><b>Value</b></td>
</tr>
<?php
  for ($i = 0; $i < mysqli_num_rows($result); $i++) {
      echo "<TR>";
$row_array = mysqli_fetch_row($result);
      for ($j = 0; $j < mysqli_num_fields($result); $j++)
{
echo "<TD>" . $row_array[$j] . "</td>";
      }
      echo "</tr>";
}
?>
</table>
<?php } ?>
</body>
</html>


Thank you very much for the help.

I went around looking at other people you helped and I found someone that fixed it, by copying the php.ini in c:windows to the php directory and IT FINALLY WORKED...

Now i'm gonna hit the tutorials... so I can... AT LAST learn PHP and MYSQL...

Thanks again:)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.