0

I use Linux Debian

Local Lamp Server

i tried to make connection between Database and php :

<?php
$tf_host = 'localhost' ; 
$tf_dbname = 'tinyforum' ; 
$tf_username = 'root';
$tf_password = '' ;

$tf_handle = mysql_connect($tf_host , $tf_username , $tf_password);

if (!$tf_handle)
die('connection problem ..');
$tf_db_result = mysql_select_db($tf_dbname);
if($tf_db_result)
{
mysql_close($tf_handle);
die('selection problem');
}

die('OK');
mysql_close($tf_handle);
?>

The result :

http://www.foxpic.com/V0HrSdgb.png

pic of phpmyadmin:

http://www.foxpic.com/V0AlRhi6.png

the place where i save the php file :

/var/www/html/

  • If you can, you should [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) [statements](http://php.net/manual/en/pdo.prepared-statements.php) instead, and consider using PDO, [it's really not hard](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Jun 19 '15 at 21:01

1 Answers1

0

Unless you copied your code incorrectly, your check is not going to result in what you want.

$tf_db_result = mysql_select_db($tf_dbname);
if($tf_db_result)

your selection seems fine so either you should change your code to

if(!$tf_db_result) //note the !

or restructure your code

if($tf_db_result) {
     //Do the stuff you want to do when you are connected
} else {

 //Die connection
}
Danprime
  • 260
  • 2
  • 11