Search the Community
Showing results for tags 'connection error'.
-
Hi all ! I have been using this snippet below to study exceptions: <?php mysqli_report(MYSQLI_REPORT_STRICT); try { $connection = new mysqli('localhos', 'root', '', 'test') ; } catch (Exception $e ) { echo "Server Error"; } ?> If, as in the snippet, I misspell the localhost, I am unable to override the php's own message. If, on the other hand I just misspell say the database name with the host spelt correctly, it overrides the php's default message. ( Default messages in both examples above being different). with the host name misspelt I receive the following warning: With the host name correct but a wrong database name I get the message defined in the snippet. Namely "Server Error". Kindly help resolve this. Thanks very much.
-
i just created a new website for my local school i want to create a databse which will contain roll number ,marksof variosu subjects & name of students i created the database but now when i am trying to create a php script to enter students details i am having prouble in connection access denied for user 'abc'@'localhost' todatabse 'abc_db' what am i doing wrong ?? i think its because of user dont have proper privileges, how to give user privileges ?
-
Undefined variable: db_hostname in C:\xampp\htdocs\
Ordinary_Shepp posted a topic in PHP Coding Help
Hello ! I am new in php coding. So if you please help me in this regards I'll be very happy. I have received some error while connection to my mqsql database to a php file. At first I post my code.... "login.php" <?php $db_hostname = 'localhost' ; $db_database = 'PC' ; $db_username = 'admin' ; $db_password = 'maruf' ; ?> "func.php" <?php require_once('C:\xampp\htdocs\PC\login.php') ; function connect(){ $db_server = mysql_connect( $db_hostname , $db_username , $db_password ) ; if( !$db_server )die ( "Unable to connect to MySql : ".mysql_error()) ; mysql_select_db( $db_database ) or die("Unable to select database: ".mysql_error()) ; } function close(){ mysql_close() ; } function division(){ $mydata = mysql_query("SELECT * from division order by zeocode"); if( !$mydata ) echo "Database connection failed. ".mysql_error().'<br>' ; while( $record = mysql_fetch_array($mydata)){ echo '<option value ="' . $record['$name'] . '">' . $record['$name'] . '"</option>'; } } ?> "form.php" <?php require_once 'func.php'; connect() ; ?> <!DOCTYPE html> <html> <head> form </head> <body> <header> <h1 align='center'>Census</h1></header> <p> <select name ="division"> <?php query() ?> </select> <?php close() ?> </p> </body> </html> It shows me the following error . calling from the browser -> http://localhost/PC/form.php Notice: Undefined variable: db_hostname in C:\xampp\htdocs\Population_Census\func.php on line 10 Notice: Undefined variable: db_username in C:\xampp\htdocs\Population_Census\func.php on line 10 Notice: Undefined variable: db_password in C:\xampp\htdocs\Population_Census\func.php on line 10 Notice: Undefined variable: db_database in C:\xampp\htdocs\Population_Census\func.php on line 12 Unable to select database: No database selected then I change form.php into this <?php //require_once('C:\xampp\htdocs\Population_Census\login.php') ; $db_hostname = 'localhost' ; $db_database = 'PC' ; $db_username = 'admin' ; $db_password = 'maruf' ; function connect(){ $db_server = mysql_connect( $db_hostname , $db_username , $db_password ) ; if( !$db_server )die ( "Unable to connect to MySql : ".mysql_error()) ; mysql_select_db( $db_database ) or die("Unable to select database: ".mysql_error()) ; } function close(){ mysql_close() ; } function division(){ $mydata = mysql_query("SELECT * from division order by zeocode"); if( !$mydata ) echo "Database connection failed. ".mysql_error().'<br>' ; while( $record = mysql_fetch_array($mydata)){ echo '<option value ="' . $record['$name'] . '">' . $record['$name'] . '"</option>'; } } ?> which show me exactly same problem.