Help Connecting Php With Mysql

Welcome. Please Login, Register, Or Activate! 
type your username and password to login
Date: November 24, 2009, 11:56 AM
431784 members and 298777 Topics
Latest Member: pels
Nairaland [Nigerian Forum] Home Help Search Who is currently online? Login Register
Nairaland Forum  |  Technology  |  Webmasters (Moderators: OmniPotens, yawa-ti-de)  |  Help Connecting Php With Mysql
Pages: (1) Go Down Send this topic Notify of replies
Author Topic: Help Connecting Php With Mysql  (Read 204 views)
timbalogs
Help Connecting Php With Mysql
« on: April 28, 2007, 05:49 PM »

I run mysql and php on windows xp(using IIS), I run simple scripts on the php engine and it responds, but connecting to the mysql database is a headache.
When i run scripts like this inside my html script:
<html>
<body>
<?php
$dbcnx = @mysql_connect('localhost', 'user', 'psswd') or die('Unable to connect');
$pick_db = @mysql_select_db('newdb') or die('unable to choose db');
?>
</body>
</html>

what i get is a blank browser screen, and when i check the source code, the opening <body> tag is where the code ends.
Pls any help as how i can sucessfully connect to the database?
my2cents (m)
Re: Help Connecting Php With Mysql
« #1 on: May 02, 2007, 05:07 PM »

If i understand your post, it is not a surprise you are printing blanks.  All you have done is connect to your DB and to a table.  There is no interaction (as in no select *, or whatever SQL action you want to perform) whatsoever, based on your code here, b/w you and the DB.

Try adding some kind of action and I bet you will get results.

I hope this helps.
unixman
Re: Help Connecting Php With Mysql
« #2 on: May 07, 2007, 10:15 AM »

Hey why are you running PHP with ISS? You are better off with Apache. For your development environment, you can use Windows but if you have got another machine, you can use Linux or any other UNIX variants. I mean you can code and design your web interface Windows while you run your scripts on Linux on another box.

Configuring PHP, MySQL and Apache individually can be challenging for a newbie but there are helpful one-install products that will help. My favourite is XAMPP available at http://www.apachefriends.org/en/xampp.html. This is the link to download the Windows installer one - http://www.apachefriends.org/download.php?xampp-win32-1.6.1-installer.exe.  I recommend this one. Please remember to disable or change the port for ISS. You might also have to take care of your previous MySQL installation. XAMMP will install Apache 2, PHP 5, MySQL 5 among others for you and configure them to work together.

Finally, here is a simple script to connect to your database.

<?

$db_name =  "mysql"; // name of your database here
$db_username = "root"; // username for database here
$db_password = ""; // password for database here


$mysql_link = mysql_connect("localhost", "$db_username", "$db_password") or die( "Unable to connect to database server");
@mysql_select_db( "$db_name") or die( "Unable to select database");

?>
 Sturvs.com - Get Free Marketing - The New Nigerian Digg.com  Website Now In Naira, Why ( You Asked, Didn't You ? )  The Facts About Us  Page 2
Pages: (1) Go Up Send Topic to Friend by E-mail Reply 


Sections: Autos/Cars (2) Jobs/Vacancies (2) (3) Career Talk Education General(2) Politics Romance Computers Phones Travel
Sports Fashion Health Religion Celebrities TV/Movies (2) Music/Radio (2) Books Webmasters Programming

Links: Page1 Page2 Page3 Page4 Page5 Page6 Page7 Page8 Page9 Page10

Nairaland is owned by Oluwaseun Osewa. See also: Nairalist Classified Ads
Nairaland Forum | Powered by SMF 1.0.12.
© 2001-2005, Lewis Media. All Rights Reserved.