<?php
//database connectivity
$connect_error='Sorry We could not able to connect to the database';
mysql_connect('localhost','root','') or die($connect_error);
mysql_select_db('beehive_intwebpage') or die ($connect_error);
?>
We have this in setup this in our localhost. When there no connection with the database we get the error along with the error message.
Warning: mysql_connect(): No connection could be made because the target machine actively refused it. in D:\core\database\connect.php on line 3
Sorry We could not able to connect to the database
How to show only the message and not the default sql error.
Thanks!
First: Don't use mysql_*-methods anymore, they're deprecated. Instead use mysqli or PDO.
For your error, disabling the error-reporting according to this documentation should help.
Just add error_reporting(0); to the beginning of your file.
Hey default errors are caused due to php itself, you can turn them off in the php configuration file and you have to turn them off really because watching errors give an attacker knowledge of how your site works and your sites internal structure. So just turn off the error_reporting in php configuration
Related
I have implemented a phpGrid that works in my dev environment but just keeps saying:
Error: Could not connect to the database
in production
I am logging failed attempts at MySQL connections in the logs on and if I put in a dodgy username and password in the conf.php files username/password it does not show up in the log (I've tested the log is working by attempting to connect with bad credentials via a terminal.
The host is just "localhost" I am using PDO connections elsewhere within my code and the are all connecting using "localhost" so I see now reason why this would be a problem.
In the conf.php I've turned on:
define('DEBUG', true);
And on my grid I have:
$dg -> enable_debug(true);
But I just keep getting this stupid error that tells me nothing about what's really going on...
It happened to me as well. Finally I was able to figure out. The reason is mySQLi was not enabled on the server. I enabled it and it works now.
Sorry, i cannot add a commant and sorry for my english.
If you are using PHP 5.5 try:
error_reporting=E_ALL^E_DEPRECATED
at top of the page for the time being.
For the files on your production machine: proof if they are still in utf-8 encoding
I'm trying to connect to an MSSQL database with PHP and encounter a very frustrating error while trying to connect. It loads for a minute, before printing out the following message:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[08001]:
[Microsoft][SQL Server Native Client 11.0]Named Pipes Provider: Could not open a connection to SQL Server [53].
Here's my connection string:
DB::config("sqlsrv:Server={$dbHost} ; Database={$dbName}", $dbUser, $dbPass);
And in my DB class:
public static function config($dsn, $user, $pass)
{
self::$_pdo = #new PDO($dsn, $user, $pass);
...// intentionally left out
I'm very baffled. I have the following module configured in my php.ini file: extension=php_pdo_sqlsrv_54_ts.dll. Although I think I installed it right and I don't receive any error message about the driver not working, this bit of PHP prints nothing:
if (function_exists( 'sqlsrv_connect' ))
echo "hey";
and as you can see from my error message above SQL Server Native Client 11 appears to be working. I'm on a Windows platform. I tried disabling the firewall to no avail. I don't have much information about the SQL server or I would share it here.
This is my first time posting on Stack, so I apologize if I'm leaving out a key piece of information or I'm not following proper etiquette in some way, but any help is definitely appreciated.
Also, I should add that I've already done too much Googling, and haven't had any success.
My install process actually worked, but the connection was indeed invalid. I should have been using the IP address as the host name, which I was not. I was also using a colon instead of a comma before the port number. Finally, no spaces can be allowed in the connection string, which I thought would be automatically stripped out. So, here's a valid connection string for those of you that may find yourself in a similar predicament:
$connectionString="sqlsrv:Server=123.123.12.1,9864;Database=mssqldatabaseWootWoot";
Also, in response to my earlier observation about that function sqlsrv_connect, I had not enabled the driver necessary for that function. It is located in php_sqlsrv_54_ts.dll, which after enabling, reported the function as existing.
Thanks to anyone who put any time into solving this.
I ran into the same problem but I found that I did not need to use the IP address, the server name worked just fime. Also I was not sure what port my server was using, I found the information here: How to find the port for MS SQL Server 2008?
I also found the following links helpful in getting PDO to work:
PHP PDO Connection to SQL Server with integrated security?
Use of PDO in classes
MS SQL Server (PDO) — Microsoft SQL Server Functions (PDO_SQLSRV)
I know ncksllvn solved his problem so I hope this helps whoever else visits!
Warning: mysqli_connect(): (HY000/2002): No connection could be made because the target machine actively refused it. in E:\xampp\htdocs\ss\docs\regional.php on line 15
The connection to the database could not be established.
Is this a serious error or can easily be ignored? The error message 'The connection to the database could not be established.' is expected to pop but not the warning text. How do I remove it in that case. Below is the code I've used.
$db = mysqli_connect('localhost', 'root', '', 'regional_data');
if(mysqli_connect_errno()) {die('The connection to the database could not be established.');}
EDIT: I have stopped SQL in the development area to test this and the message occurs at that time.
In your development environment it is completely legal to have the settions of display_errors on. This is the most easy way to see if things go wrong.
In productive environment you wouldn't set this to on, because the user usually does not need to know if PHP things go wrong - he even should not, because these messages might contain valuable information for attackers. That should only be communicated through dedicated error messages like inside your die()
So the warning in your output will go away if you disable display_errors, but you really want to have this warning in your logfile. Suppressing the warning with an # is not reccommended!
Probably only going to show the warning in your development environment due to how you have error_reporting and display_errors set.
error_reporting
ini_set('display_errors', 0)
edit: Just to clarify, if your error_reporting level includes warnings in your dev environment, they can be included in errors displayed to screen. To test, set displays_errors to 0, as above right before that mysqli connect.
You can suppress the warning by calling the function prepended with #, but better to be sure to fix the source of the error.
e.g. $db = #mysqli_connect(...)
I am using SQL Server as my backend for program.when i am try to connect with database which not shows any type of errors,but it is not working.Which is not getting connection.
My code is like
mssql_connect('servername', 'db_user', 'db_password') or die('Error');
The funny thing is which is not connecting and also which is not show message Error.
How can we enable SQL Server configuration using php program (what is the script for that.not manually). How could we know the actual status of SQL Server in server?
My application is working properly in local;the problem is about public hosting.
turn on error_reporting in your php.ini. it might be some other section of code that is causing the issue, since you say that it doesn't go to die part. try checking first if it even goes to the mysql_connect() part. if possible post a part of your code around the mysql_connect.
I would bet it is localhost, I have, nor do I ever wish to, see the database sitting on the same server as the website. Check in your hosting control panel for the proper connection string.
I have narrowed down my problem to the mysql_connect call I am doing in PHP.
It produces an error message. What would you suggest I should do to fix the problem with this error:
Error Summary
HTTP Error 500.0 - Internal Server Error
The page cannot be displayed because an internal server error has occurred.
Detailed Error Information
Module IsapiModule
Notification ExecuteRequestHandler
Handler PHP
Error Code 0x00000000
Requested URL http://localhost:80/getuser.php?q=3&sid=0.2953613724031635
Physical Path C:\inetpub\wwwroot\getuser.php
Logon Method Anonymous
Logon User Anonymous
Most likely causes:
IIS received the request; however, an internal error occurred during the processing of the request. The root cause of this error depends on which module handles the request and what was happening in the worker process when this error occurred.
IIS was not able to access the web.config file for the Web site or application. This can occur if the NTFS permissions are set incorrectly.
IIS was not able to process configuration for the Web site or application.
The authenticated user does not have permission to use this DLL.
The request is mapped to a managed handler but the .NET Extensibility Feature is not installed.
Things you can try:
Ensure that the NTFS permissions for the web.config file are correct and allow access to the Web server's machine account.
Check the event logs to see if any additional information was logged.
Verify the permissions for the DLL.
Install the .NET Extensibility feature if the request is mapped to a managed handler.
Create a tracing rule to track failed requests for this HTTP status code. For more information about creating a tracing rule for failed requests, click here.
Links and More InformationThis error means that there was a problem while processing the request. The request was received by the Web server, but during processing a fatal error occurred, causing the 500 error.
Microsoft Knowledge Base Articles:
294807
Check phpinfo() for presence of MySQL functions. If those exist, try connecting to other MySQL servers. Try to narrow down if the problem is with your code, your PHP library, your SQL server or your web server by changing variables. CHeck for logs, I know Apache has an error log where detailed PHP error information goes -- IIS probably has something similar. Consider recompiling and reinstalling PHP.
Though Avinash mentioned apache, he may be on the right track in the sense that you could be missing the actual library for mysql to interact with IIS. I didn't read through the whole thing, but this may help you out: http://www.atksolutions.com/articles/install_php_mysql_iis.html
Also, I saw your response to Josh... You should have a table in your phpinfo for mysql.
Just a reminder to new version PHP users:
mysql_connect was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used.
Example (MySQLi Object-Oriented) of you should use instead of myslq_connect:
<?php
$servername = "localhost";
$username = "username";
$password = "password";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
check you apache conf file
and remove comment from the line below
(simply remove # from begining of the line)
LoadModule isapi_module modules/mod_isapi.so