aimseeker Posted February 28, 2010 Share Posted February 28, 2010 hey everyone!!!! well i have got a problem with connecting to a mysql database using php. I used this package "mysql-noinstall-5.1.44-win32.zip" and extracted it to c:\mysql and added c:\mysql\bin to the PATH variable and used the following command in command prompt to start mysql: c:\mysql\bin\mysqld --standalone well mysql did start and everything went well accessing mysql in command prompt. Well under the database "mysql" in the table "user" i created a new user "php" with a password="****" and hostname = "localhost" but when i try to access this database with a following php routine: //test.php <?php $username = "php"; $password = "****"; $hostname = "localhost"; echo $hostname; $connection = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); echo "Connected to MySQL"; ?> and when i accesses it with my browser using localtost/test.php, all i get is "localhost" displayed on screen, "Connected to mysql" never gets displayed not i get any error.. note: i am using windows 7(32-bit-ultimate)and mysql 5.1.44. any help will be appreciated....thxxx Quote Link to comment https://forums.phpfreaks.com/topic/193691-problem-connecting-to-database/ Share on other sites More sharing options...
PFMaBiSmAd Posted February 28, 2010 Share Posted February 28, 2010 Please set error_reporting to E_ALL and display_errors to ON in your master php.ini so that php will help you by reporting and displaying all the errors it detects. You will save a TON of time. Stop and start your web server to get any change made to your master php.ini and confirm that the settings are actually changed by using a phpinfo() statement (in case the php.ini that you are changing is not the one that php is using.) Quote Link to comment https://forums.phpfreaks.com/topic/193691-problem-connecting-to-database/#findComment-1019608 Share on other sites More sharing options...
aimseeker Posted March 1, 2010 Author Share Posted March 1, 2010 ok now i set display_error "ON" in php.ini file and now its displaying this error for my mysql_connect() command: Fatal error: Call to undefined function mysql_connect() in C:\webroot\test.php on line 7 any ideas?? Quote Link to comment https://forums.phpfreaks.com/topic/193691-problem-connecting-to-database/#findComment-1019852 Share on other sites More sharing options...
PFMaBiSmAd Posted March 1, 2010 Share Posted March 1, 2010 The mysql_xxxxx functions are not available for php to use because the mysql extension needs to be enabled in your master php.ini Quote Link to comment https://forums.phpfreaks.com/topic/193691-problem-connecting-to-database/#findComment-1019857 Share on other sites More sharing options...
aimseeker Posted March 1, 2010 Author Share Posted March 1, 2010 dude can u refer any manual or something coz i am not getting u completely..... thxxx Quote Link to comment https://forums.phpfreaks.com/topic/193691-problem-connecting-to-database/#findComment-1019858 Share on other sites More sharing options...
aimseeker Posted March 1, 2010 Author Share Posted March 1, 2010 ok to be more specific i found these settings about mysql in php.ini: [MySQL] ; Allow or prevent persistent links. mysql.allow_persistent = On ; Maximum number of persistent links. -1 means no limit. mysql.max_persistent = -1 ; Maximum number of links (persistent + non-persistent). -1 means no limit. mysql.max_links = -1 ; Default port number for mysql_connect(). If unset, mysql_connect() will use ; the $MYSQL_TCP_PORT or the mysql-tcp entry in /etc/services or the ; compile-time value defined MYSQL_PORT (in that order). Win32 will only look ; at MYSQL_PORT. mysql.default_port = ; Default socket name for local MySQL connects. If empty, uses the built-in ; MySQL defaults. mysql.default_socket = ; Default host for mysql_connect() (doesn't apply in safe mode). mysql.default_host = ; Default user for mysql_connect() (doesn't apply in safe mode). mysql.default_user = ; Default password for mysql_connect() (doesn't apply in safe mode). ; Note that this is generally a *bad* idea to store passwords in this file. ; *Any* user with PHP access can run 'echo get_cfg_var("mysql.default_password") ; and reveal this password! And of course, any users with read access to this ; file will be able to reveal the password as well. mysql.default_password = ; Maximum time (in seconds) for connect timeout. -1 means no limit mysql.connect_timeout = 60 ; Trace mode. When trace_mode is active (=On), warnings for table/index scans and ; SQL-Errors will be displayed. mysql.trace_mode = Off ; 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_mysql.dll can u help me adjust these values?? thxxxx Quote Link to comment https://forums.phpfreaks.com/topic/193691-problem-connecting-to-database/#findComment-1019891 Share on other sites More sharing options...
aimseeker Posted March 1, 2010 Author Share Posted March 1, 2010 ok this post solved my problem!!! 1.Search your server for libmysql.dll. Delete any instance of libmysql.dll that is not in the C:\PHP directory. This limits the possibility of older MySQL client API's being used with PHP. 2.Search your server for php_mysql.dll. Delete any instance of php_mysql.dll that is not in the C:\PHP directory. This limits the possibility of older MySQL client API's being used with PHP. 3.Open your C:\%WIN%\php.ini file in a text editor (Notepad will work). Search for the line that looks like --> ;extension=php_mysql.dll Change this line to --> extension=php_mysql.dll Uncomment: extension_dir="c:\php\ext" Save the modified php.ini file. 4. Copy php.ini to C:\%WIN%\System32 5. Copy C:\PHP\libmysql.dll and C:\PHP\ext\php_mysql.dll to the C:\%WIN%\system32 folder. thxxx everyone!!! Quote Link to comment https://forums.phpfreaks.com/topic/193691-problem-connecting-to-database/#findComment-1019932 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.