Page 1 of 1

php connection with mysql database

Posted: Mon Nov 16, 2009 10:55 am
by izzul_apit
i am beginner in php,i just want to ask

how to connect php and mysql server.i had install php 5.2.11,mysql sever 5.1 and mysql administrator 5.1.40.i using IIS version 5.1 and windows xp sp2.when i try to connect mysql and php,error was display.an error sound like that "Fatal error: Call to undefined function mysql_connect() in C:\Inetpub\wwwroot\test.php on line 7".
my coding is:-
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

// some code
?>


for information i was tried many times to solve this matter.could anyone help me ?...please.

Re: php connection with mysql database

Posted: Mon Nov 16, 2009 1:05 pm
by akuji36
connection by mysql with php

Code: Select all

<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
 
mysql_select_db("my_db", $con);
 
$result = mysql_query("SELECT * FROM Persons");
 
while($row = mysql_fetch_array($result))
  {
  echo $row['FirstName'] . " " . $row['LastName'];
  echo "<br />";
  }
 
mysql_close($con);
?>
Person is the table name
field names = FirstName And LastName

database name = my_db

above code when modified will give you your db data

thanks

Rod

Re: php connection with mysql database

Posted: Mon Nov 16, 2009 4:54 pm
by iankent
izzul_apit wrote:Fatal error: Call to undefined function mysql_connect()
that bit would make me think that PHPs mysql extension isn't enabled - check your php.ini file and make sure there's no semi-colon before this line:
extension=php_mysql_libmysql.dll

hth

edit: you'll probably need to restart IIS once if you change php.ini

Re: php connection with mysql database

Posted: Mon Nov 16, 2009 8:39 pm
by izzul_apit
it`s that u mine:-

....................................................................................................................................................................

;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;
;
; If you wish to have an extension loaded automatically, use the following
; syntax:
;
; extension=modulename.extension
;
; For example, on Windows:
;
; extension=msql.dll
;
; ... or under UNIX:
;
; extension=msql.so
;
; Note that it should be the name of the module only; no directory information
; needs to go here. Specify the location of the extension with the
; extension_dir directive above.


; 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_bz2.dll
;extension=php_curl.dll
extension=php_dba.dll
extension=php_dbase.dll
;extension=php_exif.dll
;extension=php_fdf.dll
extension=php_gd2.dll
extension=php_gettext.dll
;extension=php_gmp.dll
;extension=php_ifx.dll
extension=php_imap.dll
;extension=php_interbase.dll
extension=php_ldap.dll
extension=php_mbstring.dll
;extension=php_mcrypt.dll
;extension=php_mhash.dll
;extension=php_mime_magic.dll
;extension=php_ming.dll
extension=php_msql.dll
extension=php_mssql.dll
extension=php_mysql.dll
extension=php_mysqli.dll
;extension=php_oci8.dll
;extension=php_openssl.dll
;extension=php_pdo.dll
;extension=php_pdo_firebird.dll
;extension=php_pdo_mssql.dll
;extension=php_pdo_mysql.dll
;extension=php_pdo_oci.dll
;extension=php_pdo_oci8.dll
;extension=php_pdo_odbc.dll
;extension=php_pdo_pgsql.dll
;extension=php_pdo_sqlite.dll
extension=php_pgsql.dll
;extension=php_pspell.dll
;extension=php_shmop.dll
;extension=php_snmp.dll
;extension=php_soap.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
extension=php_zip.dll


....................................................................................................................................................................

it`s that i have done,please check.thanks for advice,iankent.

Re: php connection with mysql database

Posted: Mon Nov 16, 2009 11:23 pm
by califdon
Your configuration file tells PHP to use a file named php_mysql.dll. The first thing to check is whether you have a file with that name. If you don't, that explains why it doesn't recognize the command mysql_connect. The other thing, as it says in the instructions, is make sure you set the extension_dir directive to the folder in which all these .dll files are located. Otherwise, PHP will not be able to find them.

Re: php connection with mysql database

Posted: Tue Nov 17, 2009 12:22 am
by izzul_apit
califdon,thanks you

i will try............. 8O