0

I am much confuse about 000webhost database uploading I have set my database at their and accessing it with username and password perfectly. Now trying to connect with through PHP code but i am failed, getting 500 error code and no details of the error although I have also logged exception message in my connection code nuto it only showing "A Connection error has occurred" and nothing more:

//DB Configuration $hostName = 'localhost'; $dbUserName = 'id143984_jw_kioskuser'; $dbPassword = '***********'; $databaseName = 'id143984_jw_kiosk'; try{ $dbHandler = new PDO('mysql:host='. $hostName . ';dbname='. $databaseName, $dbUserName, $dbPassword); } catch(PDOException $ex){ echo '<h1>A Connection error has occurred.</h1><pre>', $e->getMessage() ,'</pre>'; echo $e->getMessage(); } 

My current DB interface at 000webhost saying me that "Use localhost as connection hostname" while in another post of 000WEbhost saying "Never use 'localhost' as your MySQL hostname! You can find your MySQL hostname by logging on to members area, entering control panel and clicking on MySQL icon."

HOw do i make successfull connection?

6
  • enter the url to your mysql-server insted of "localhost" Commented Nov 7, 2016 at 8:08
  • @Blueblazer172 make sure your db configuration in your connection are correct and matches to the hosting db configuration Commented Nov 7, 2016 at 8:12
  • @Blueblazer172 databases.000webhost.com is the database url Commented Nov 7, 2016 at 9:16
  • @NewbeeDev how you will do this? i have matched all the things. confusion about the host name as question stated Commented Nov 7, 2016 at 9:17
  • replace "localhost" with "databases.000webhost.com" Commented Nov 7, 2016 at 9:18

2 Answers 2

3

Finally i managed to get the answer through mysql query thanks to Show MySQL host via SQL Command Answer at stack I run below query and got the host name and use it in my php it worked now.

 select @@hostname; show variables where Variable_name like '%host%'; 
Sign up to request clarification or add additional context in comments.

1 Comment

where and to run this query to get host name of 000webhost free
-2
$hostName = 'mysql6.000webhosting.com'; $dbUserName = 'id143984_jw_kioskuser'; $dbPassword = '***********'; $databaseName = 'id143984_jw_kiosk'; $con = mysql_connect($hostName,$dbUserName,$dbPassword); if (!$con) { die('Could not connect: ' . mysql_error()); }`enter code here` mysql_select_db("$databaseName",$con); 

this should give you the real reason and note the correct host name

1 Comment

where did you find host name? and i am not willing to use old sql connection. i want pdo

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.