Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problems with mysql and php configuration...Please Help!!! 1

Status
Not open for further replies.

codespree

Technical User
Feb 6, 2006
5
US
Hello there,
i installed php version 5 and then mysql ver. 5 and my webserver is iis..in windows XP. when i tried to run the following simple code to test my database connection i get the following error -->

Fatal error: Call to undefined function mysql_connect() in c:\Inetpub\ on line 5

the code i used is:
<?php
$username = "";
$password = "root";
$hostname = "localhost";
$dbh = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
print "Connected to MySQL<br>";
$selected = mysql_select_db("first_test",$dbh)
or die("Could not select first_test");
// you're going to do lots more here soon
mysql_close($dbh);
?>


then i made changes in the following areas :

; Directory in which the loadable extensions (modules) reside.
extension_dir = "C:\Program_Files\php\ext"
.
.
.
.
.
; Windows Extensions
; Note that ODBC support is built in, so no dll is needed for it.
; Note that many DLL files are located in the extensions/ (PHP 4) ext/ (PHP 5)
; extension folders as well as the separate PECL DLL download (PHP 5).
; Be sure to appropriately set the extension_dir directive.

;extension=php_mbstring.dll
;extension=php_bz2.dll
;extension=php_curl.dll
;extension=php_dba.dll
;extension=php_dbase.dll
;extension=php_exif.dll
;extension=php_fdf.dll
;extension=php_filepro.dll
;extension=php_gd2.dll
;extension=php_gettext.dll
;extension=php_ifx.dll
;extension=php_imap.dll
;extension=php_interbase.dll
;extension=php_ldap.dll
;extension=php_mcrypt.dll
;extension=php_mhash.dll
;extension=php_mime_magic.dll
;extension=php_ming.dll
;extension=php_mssql.dll
:extension=php_msql.dll
;extension=php_mysql.dll <-------- when i removed the semi-colen...and when i tried to
run my script i get an error saying
unable to laod mysql and mysqli dll's.
;extension=php_mysqli.dll <--------

;extension=php_oci8.dll
;extension=php_openssl.dll
;extension=php_oracle.dll
;extension=php_pgsql.dll
;extension=php_shmop.dll
;extension=php_snmp.dll
;extension=php_sockets.dll
;extension=php_sqlite.dll
;extension=php_sybase_ct.dll
;extension=php_tidy.dll
;extension=php_xmlrpc.dll
;extension=php_xsl.dll


so please give me a solution to work on php and mysql...

thank you..

ahmed
 
yeah my extension dll's reside in "C:\Program_Files\php\ext"...


ahmed
 
On Win32, you're not going to have access to those files unless you've uncommented one or the other. You're trying to use the mysql_* family of functions, so leave mysqli_* commented out.

"Program[red]_[/red]files" is a non-standard Win32 directory name. It shouldn't matter, though.



Want the best answers? Ask the best questions! TANSTAAFL!
 
if i try to uncomment it ...i get an error "unable to load the particular dll"

so is there is any other possible solution..

thanx ahmed
 
But you must get PHP to work with one or the other line uncommented in order to use PHP with MySQL. Otherwise the library will not be loaded and the functionality will not be available.



Want the best answers? Ask the best questions! TANSTAAFL!
 
This is kind of a question and suggestion. Since you are working on a Windows machine shouldn't you use forward slashes '/' instead of back slashes '\' ?

Also on my Windows machine I sent my extension directory to:
extension_dir = "./"

And all is well...
 
BTW - my extensions directory resides within the PHP directory.
 
That's true. PHP seems to do better if one uses forward slashes for directory tree delimiters rather than the MS-standard backslash.



Want the best answers? Ask the best questions! TANSTAAFL!
 
hey guyz thanx a lot atlast the whole php and mysql is working .....i jus played around as u all said..tried pasting few library dll's files and it worked....restarted my iis couple of times for every change....some how it worked...

thank u all for the help...

* special thanx to sleipnir214
ahmed
 
hey sleipnir214,
can u tell me do's and dont's in php ,mysql and apache sever when ur coding....

it wud help me in the future,

thanx
ahmed
 
Here's two cents' worth from the top of my head:

PHP:[ul][li]DON'T install PHP modules you don't need.[/li][li]DO pick an indentation style that suits you and stick to it religiously. The classic ones are listed at . I personally prefer what they call BSD/Allman style, but that's just my opinion. Also, always put the braces in your conditional blocks, even if you don't need them. For example, in the snippet:
Code:
if ($foo == $bar)
{
   print "yes";
}
else
{
   print "bar";
}
the curly braces are unnecessary. But they will be useful to have in place when code is deeply nested or when I want to add functionality to the execution blocks.[/li][li]DO make yourself familiar with the PHP online manual: It is your single best source for information on the language.[/li][li]Do always code as if register_globals is set to "off". Make sure you understand what is talked about here: [/li][li]DON'T trust input from users. They will misspell words, diddle with values, and cause all sorts of other mischief, either deliberately or accidentally. Check all values, particularly ones that you will end up storing in your datbase.[/li][li]DO add the extra code to check for bugs and make sure your code can give you what you need to debug it. However, DON'T let your users see this debugging information -- all a user needs to know is that something went "whoops", not that your code got a "parse error in line 443 of foo.php".[/li][li]DO use PHP's superglobal arrays ( directly in your code. Don't copy values to other variables or a function like extract() to dump a superglobal's values. It makes your code easier to understand down the road to see that a value is coming from $_POST.[/li][li]DON'T use a url with include() or require() if that url is pointing back to your own server. There is very rarely a real need for this and the url-include will slow your scripts down and use more web server resources[/li][li]DO store the sensitive data the script needs outside the document root. PHP's include() functions can include a file from anywhere on the server's filesystem, so there is no reason to not put your database passwords in an include file somewhere where it's impossible to get to it via the web.[/li][li]DON'T use elseif -- it's simply an unnecessary part of the language and can make your code very difficult to understand. Nested if-else blocks or a switch statement are nearly always more readable[/li][/ul]

MySQL:[ul][li]DO make MySQL's database engine do as much of the work as possible. It is specifically optimized to manipulate data faster than your code can.[/li][li]DON'T fetch more from MySQL than you need. If you need to know how many items there are for a given criterion, then issue a SELECT query that asks for a COUNT. Don't perform a more general SELECT and use mysql_num_rows() to get the answer.[/li][li]DO keep in mind that when you are writing a database application, your database tables are a part of the datastructures of your application. Don't think of the database and your variables in memory as separate things, because they really aren't. It's just one type of storage is easier to access than the other.[/li][/ul]

Apache:[ul][li]DON'T load modules you don't need.[/li][li]DO keep your httpd.conf as simple as possible.[/li][li]DO store sensitive information, like .htpasswd files, outside of the document root. You can configure Apache to not send those files, but you might forget one Apache installation. So it's a good habit to get into.[/li][/ul]



Want the best answers? Ask the best questions! TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top