simple PHP code not working????

Hello all
I am just starting out with PHP and i am running into some problems.

I have a windows xp sp2, mysql5 php5 running. I checked to see if everything is running correctly i uses this code

[php]
<$php
phpinfo();
?>
[php]
everythings seems to be working.

but when i try this code.
[php]

<?php error_reporting("E_ALL"); $host = 'localhost'; $user = 'username'; $pass = 'password'; $db = 'mydb'; $connection = mysql_connect($host, $user, $pass) or die('This is an error'); echo('you are connected to the DB'); ?>

[php]
nothing displays on in the browser???
I think it has to do with the connection string becase if i comment it out i will get the echo statment.

let me know what you all think?
Chris

u should remove ur user and pass from ur post (replace it with something like $user = ‘username’; $pass = ‘password’; )

is ‘This is an error’ getting displayed?

try $connection = mysql_connect($host, $user, $pass) or die(mysql_error());

and most important: error_reporting(E_ALL); has to be written without quotes!

I made the changes you requested and still nothing is displayed in the browser.

[php]

<?php error_reporting(E_ALL); $host = 'localhost'; $user = 'user'; $pass = 'pass'; $db = 'mydb'; $connet = mysql_connect($host, $user, $pass) or die(mysql_error()); mysql_select_db($db) or die(mysql_error()); echo '
'; echo('you are connected to the DB'); echo '
'; echo ($user); ?>

Ok from what i can see if i try to connect to a fake db it tells me the it can’t connect to the db…

To me i looks like the connect string is working? am i right?

i am using the Zend dev studio for coding is there any thing better?

So i guess my problem is that nothing between the <?php ?> is displayed in the browser on my localhost…

have u tryed to look at the html-source in ur browser?

yup this is what i see and nothing else

<html>
<head>
<title>
This is a test!!!!
</title>
</head>
<body>

I think it might be something that has to do with the setup but i am not sure.

Ok i fixed it, and this is what my problem was

well it looks like the windows install of PHP does not come with a few ext you need to run with mysql.

so first thing i had to do was go to this site and download the ext dll’s
http://us.php.net/get/php-5.2.3-Win32.zip/from/a/mirror
unziped it to the ext folder under the php folder.
( you may have to make this folder if it is not there)

next thing i did was change the php.ini file to
extension_dir = C:Program FilesApache Software FoundationApache2.2PHPext
( right around line 220)

finaly i uncommented
extension=php_mysql.dll
extension=php_mysqli.dll
(around line 660)

rebooted the the server and BAMMMMM!!!
working.

thx for shareing the solution

Sponsor our Newsletter | Privacy Policy | Terms of Service