hello to everyone here ... please i need your help . i have some trouble with php and my SGBDs ... i have installed php mysql and apache separately . but when i launch a php program with mysql_connect it send a 500 internal error without response . i have changed mysql to postgresql but it is the same problems . i have also remove the comma before some line in php.ini but it's the same result ... there is a simple connection to the database code examples `
<?php
$link = pg_connect('localhost', 'USERNAME', 'PASSWORD');
if (!$link) {`
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
pg_close($link);
`
and there is the result the result of the code with 500 error
and there is my php.ini file image of my php.ini
thanks you
According to http://php.net/manual/en/function.pg-connect.php, you need to do
pg_connect("host=localhost dbname=mary user=USERNAME password=PASSWORD");
So the format is not correct and dbname is missing from your code.
Have you restart apache ?
Set display_errors directive to On in your php.ini
Create info.php in your document root, put <? phpinfo(); ?> into it.
Open info.php from your browser, try to find word "pdo_pgsql" / "pdo_mysql". Has it appear correctly ?
Dig into your apache access_log and error_log files to get further clue about your error.
Related
I uninstalled existing XAMPP in Mac OS and installed the latest XAMPP with PHP 8.2.0 (not the VM version). Now an error-handling routine that worked before no longer works:
<?php
$conn = mysqli_connect("localhost", "root", "", "false_db_name");
if (!$conn) {
echo "Error: Unable to connect to database. ";
echo "Debugging errno: " . mysqli_connect_errno();
echo " Debugging error: " . mysqli_connect_error();
exit;
}
?>
In previous versions of XAMPP/PHP, using "false_db_name" instead of an existing database name would result in the error text being written directly into the browser window, which is handy for beginners unused to error logs.
Now, however, I just get a generic HTTP ERROR 500 and no error messages.
I would like to go back to the old way, but I don't know how to bypass the HTTP ERROR 500 page. Here's a screenshot of what it used to do:
https://imgur.com/a/CiVPa69
.
do know if this has been resolve but here is here is an useful link to help you out
solution
you just have to edit the php.ini file to enable display_error to On
I recently updated my wampserver 2.0 to wampserver 2.5.
And while i am running the php smarty code i am getting this error.
"Fatal error: Class 'DB' not found in
C:\wamp\www\livehrm.new\product\common.php on line 63"
I think it might be a pear issue of old wampserver.
Please help me
//session_start();
require_once 'DB.php';
$dbHost = $dbconfig['db_hostname'];
$dsn1[0] = array('type'=>'DB', 'dsnstuff'=>"mysql://$dbUser:$dbPassword#localhost/$dbName"); $dbdsn = "mysql://$dbUser:$dbPassword#$dbHost/$dbName";
$db = DB::connect($dbdsn);
if (DB::isError($db)) {
die ($db->getMessage());
}
?>
MySQL extension is deprecated as of PHP 5.5.0, and is not recommended for writing new code as it will be removed in the future. Instead, either the mysqli or PDO_MySQL extension should be used. Ref: http://php.net/manual/en/function.mysql-select-db.php
Update your DB.php with following code
<?php
$con = mysqli_connect("localhost","root","");
$db="livehrm";
if (!$con)
{
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con, $db) or die ("Database connection error:\n" . mysqli_error($con));
?>
There is not Class found in you provided code of file DB.php. I will update my answer when you send class code of DB
Its not the prefered solution, but this should get you working again.
I strongly recommend that you do in fact convert your code from using the mysql_* extension ot use either the mysqli_* or PDO instead as eventually this approach will not work as the developers of PHP will actually no longer provide the mysql_* extension.
But you can remove the warning messages by changing your php.ini configuration like this :-
Edit php.ini
Find this line
error_reporting = E_ALL
and change it to
error_reporting = E_ALL & ~E_DEPRECATED
Or you can just add this PHP code at the top of your db.phpscript if you dont have access to your php.ini file
error_reporting( E_ALL ^ E_DEPRECATED );
If you are using Virtual Hosts you can actually add this to the specific VH for the site that is still using the old mysql_* extension therefore not affecting other site you may be developing/maintaining
Unfortunately in a VH definition you have to use an integer value.
<VirtualHost....>
. . .
php_value error_reporting 24575
</VirtualHost>
I am a bit new to web development. So there might be a trivial thing that I might have missed and am not able to figure out by searching online for some time. Here is the problem
In my PHP script I am connecting to the data as shown below
$con = mysql_connect('localhost','root','');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
This function works fine when I run it from shell prompt on the server using "php -f" command
But when I try to execute this script using a browser session, it gives an error.
"HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request"
The server php version is 5.3.3 and it is on Cent OS.
My problem was that selinux was activated on centOS. I had to set the
allow_user_mysql_connect bool using the command
setsebool -P allow_user_mysql_connect on
I'm new to PHP, MySQL dev. I'm trying to make a simple webapp, was following a tutorial.
This is the PHP script it showed to grab info about the 'detectives' table.
<?php
$mysqli = new mysqli('localhost', 'root', 'root!', 'intrepid_detectives');
$result = $mysqli->query("SELECT * FROM detectives");
echo "<pre>";
print_r($result);
But when I open this page on my browser by going to localhost/index.php, it gives me this error:
The website encountered an error while retrieving http://localhost/index.php. It may be down for maintenance or configured incorrectly.
I asked a guy, he said the problem is with mysqli, so I searched on SO, and followed this post, but it still gives the same error.
Things to try :
can you open a simple html file in the same directory, index.html for example ?
did you try showing the errors on page with ini_set('display_errors', 1); error_reporting(E_ALL); ? Or is there something in the error.log ?
do you have a .htaccess or vhost configuration that could interfere with what you want?
Checking these will certainly point you to the right direction I hope :)
i wanna to connect to postgresql database using php but it display a blank screen when submit and doesnt execute the query
Thanks in advance
Update: this is my code
function execute_query($dbName,$query){
$host = "localhost";
$user = "postgres";
$pass = "";
$db = "test";
echo "before create connection";
$con = pg_connect ("host=$host dbname=$db user=$user password=$pass");
echo "After connection is created";
if (!$con) {
echo "not connected";
// die('Could not connect: ' . mysql_error());
}
$result = pg_query($con, $query);
pg_close($con);
return $result;
}
The output:
display the message "before connection" but doesn't display the message "After connection is created" or "not connected".
The problem is likely a PHP error that’s getting recorded to a log file somewhere. Locate the log file, or enable showing the log errors on your page by using the following at the top of your script:
ini_set('display_errors', '1');
error_reporting(E_ALL | E_STRICT);
This is a short-term solution and can’t be used in deployment (where you want to set display_errors to 0). For a long-term solution, you really want to locate the Apache or PHP error log and tail it.
To try to find the error log, run the following script:
<?php phpinfo(); ?>
In the Configuration > PHP Core section, look for error_log. If that’s not set, you can set it in your php.ini file. All errors will be recorded to that file, even if you have display_errors set to 0.
Add a php file to your server and put this in that file:
<?php
echo phpinfo();
?>
When you open that file from the browser, check if postgres support is setup for php.
you should something like this on the page:
pgsql
PostgreSQL Support enabled
PostgreSQL(libpq) Version 8.2.3
Multibyte character support enabled
SSL support disabled
Active Persistent Links 0
Active Links 0
Try checking your web server's error log (for instance, /var/log/apache2/error.log is a common location for the Apache2 log) and see if there is an error reported from PHP there.
You may want to set the php error reporting level in your ini file if this is a local development server.
It seems, that your php does not have postgresql support, cf. http://us.php.net/manual/en/ref.pgsql.php:
Note: Not all functions are supported
by all builds. It depends on your
libpq (The PostgreSQL C client
library) version and how libpq is
compiled. If PHP PostgreSQL extensions
are missing, then it is because your
libpq version does not support them.