Failed to connect mysql in centos 6.5 - php

I'm using php-mysql-apache in centos 6.5 system all requirements are exists, i think i can publish my html files in localhost but when i try to connect to mysql in php script. It doesn't appear and it shows mysql connection error.
# rpm -qa |grep php
php-pdo-5.3.3-26.el6.x86_64
php-common-5.3.3-26.el6.x86_64
php-5.3.3-26.el6.x86_64
php-mysql-5.3.3-26.el6.x86_64
php-cli-5.3.3-26.el6.x86_64
php-ldap-5.3.3-26.el6.x86_64
# rpm -qa |grep mysql
mysql-libs-5.1.71-1.el6.x86_64
mysql-community-release-el6-5.noarch
mysql-5.1.71-1.el6.x86_64
mysql-server-5.1.71-1.el6.x86_64
php-mysql-5.3.3-26.el6.x86_64
I also checked my mysql password and username are correct i try to connect as below :
$connect= mysql_connect("localhost","root","password");
if(!$connect){
echo "Failed to connect to MySQL " ;
}
Also "dynamic extensions" part of php.ini file as below :
;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;
; If you wish to have an extension loaded automatically, use the following
; syntax:
;
; extension=modulename.extension
;
; For example
;
; extension=msql.so
;
; ... or with a path:
;
; extension=/path/to/extension/msql.so
;
; If you only provide the name of the extension, PHP will look for it in its
; default extension directory.
extension=mysql.so
extension=mysqli.so
;;;
; Note: packaged extension modules are now loaded via the .ini files
; found in the directory /etc/php.d; these are loaded by default.
;;;;
I added this lines by hand;
extension=mysql.so
extension=mysqli.so
So where is my fault can do you have idea for run my php script in localhost?

Don't use mysql_connect as it is deprecated, use MySQLi or PDO to connect – it's really a pain, but check your Apache error log or enable PHP to show all errors in your scripts and it may help.

Related

Laravel Lumen image validation is not working

I'm validating a request as an image, but crashes saying:
"Unable to guess the MIME type as no guessers are available (have you
enable the php_fileinfo extension?)".
In php.ini I don't have a extension=php_fileinfo, but I do have a extension=fileinfo uncommented line (I see Lumen put this and other dependencies without the 'php_'). I also try adding extension=php_fileinfo, but when I restart Apache from XAMPP it crashes because it doesn't find that dependency. What should I do?
The code:
function updateProfilePicture(Request $request) {
$this->validate($request, [
'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048'
]);
//...
The php.ini section where fileinfo dependency is:
;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;
; If you wish to have an extension loaded automatically, use the following
; syntax:
;
; extension=modulename
;
; For example:
;
; extension=mysqli
;
; When the extension library to load is not located in the default extension
; directory, You may specify an absolute path to the library file:
;
; extension=/path/to/extension/mysqli.so
;
; Note : The syntax used in previous PHP versions ('extension=<ext>.so' and
; 'extension='php_<ext>.dll') is supported for legacy reasons and may be
; deprecated in a future PHP major version. So, when it is possible, please
; move to the new ('extension=<ext>) syntax.
;
; Notes for Windows environments :
;
; - Many DLL files are located in the extensions/ (PHP 4) or ext/ (PHP 5+)
; extension folders as well as the separate PECL DLL download (PHP 5+).
; Be sure to appropriately set the extension_dir directive.
;
extension=bz2
extension=curl
extension=fileinfo
extension=gd2
extension=gettext
Maybe is it related to that disclaimer about how to set the dependencies directives? (I'm not sure because extension=fileinfo was already in the file as a default)
I'm using windows 10 and I found the file in C:\xampp\php\ext\php_fileinfo.dll
I found the problem. I had another php.ini file with the commented line ;extension=fileinfo in C:\php\php.ini (the one I was opening was in C:\xampp\php\php.ini). Now I restarted Apache and it's working!

Why are PHP 7 PDO drivers missing?

Okay, so. I have PDO connection on MySQL database on local server. This is the code for it
<?php
$servername = "localhost";
$username = "root";
$password = "";
try {
$dbh = new PDO('localhost:host=$servername;dbname=test', $username, $password);
$dbh = null;
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
?>
When I open the page it gives me this error.
Error!: could not find a driver
It is obvious that drivers are missing but I have no idea how to install them. I already used
sudo pacman -S php
sudo pacman -S php-sqlite
sudo pacman -S mysql
Maybe I forgot some. Here is my /etc/php/php.ini file's content
;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;
; If you wish to have an extension loaded automatically, use the following
; syntax:
;
; extension=modulename
;
; For example:
;
; extension=mysqli
;
; When the extension library to load is not located in the default extension
; directory, You may specify an absolute path to the library file:
;
extension=/path/to/extension/mysqli.so
;
; Note : The syntax used in previous PHP versions ('extension=<ext>.so' and
; 'extension='php_<ext>.dll') is supported for legacy reasons and may be
; deprecated in a future PHP major version. So, when it is possible, please
; move to the new ('extension=<ext>) syntax.
;
;extension=bcmath
;extension=bz2
;extension=calendar
extension=curl
;extension=dba
;extension=enchant
;extension=exif
;extension=ftp
extension=gd
;extension=gettext
;extension=gmp
;extension=iconv
;extension=imap
;extension=intl
;extension=sodium
;extension=ldap
;extension=mysqli
;extension=odbc
;zend_extension=opcache
;extension=pdo_dblib
extension=pdo_mysql
extension=bz2.so
extension=mcrypt.so
extension=mysqli
;extension=pdo_odbc
;extension=pdo_pgsql
extension=pdo_sqlite
;extension=pgsql
;extension=pspell
;extension=shmop
;extension=snmp
;extension=soap
;extension=sockets
extension=sqlite3
;extension=sysvmsg
;extension=sysvsem
;extension=sysvshm
;extension=tidy
;extension=xmlrpc
;extension=xsl
extension=zip
It didn't let me upload the whole file so here is only part of it. If you need more details I will gladly add them in comments.
Maybe I am missing something obvious but I can't find it for a few days.
EDIT
Sorry for not pointing this out.
I am using Manjaro Linux OS
When creating the connection, your DSN has localhost as the database type...
$dbh = new PDO('localhost:host=$servername;dbname=test', $username, $password);
from the manual
$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
Also as you use single quotes, the servername will not be replaced, so use
$dbh = new PDO("mysql:host=$servername;dbname=test", $username,
Try this
sudo apt-get install php7-mysql
I think PDO extensions are missing. Add the below extensions and restart your server
For windows server -
extension=php_pdo.dll
extension=php_pdo_mysql.dll
For Linux server -
extension=pdo.so
extension=pdo_mysql.so

Class 'mysqli' not found PHP v5.6.7

On my Windows 7 machine, with PHP v5.6.7 and MySQL v5.6.23, and using PHPStorm 8, I am attempting to instantiate a mysqli object. When I try, I get:
Fatal error: Class 'mysqli' not found in...
I have also run this test, suggested here:
if (!function_exists('mysqli_init') && !extension_loaded('mysqli')) {
echo 'no mysqli :(';
} else {
echo 'we gots it';
}
The output is:
no mysqli :(
I read here that this problem is sometimes caused when it looks for the mysqli class within a namespace. I changed my code to correct this, but the issue persists
$mysqli = new \mysqli($host, $userName, $password, $database);
I read that this problem is sometimes caused when the mysqli extension is not enabled. However, I am using PHP version 5.6.7, and the mysqli extension is enabled by default on versions 5.3 and newer (according to here).
Just to be sure, I have verified that php.ini-development and php.ini-production have extension_dir = "C:/PHP/php-5.6.7/ext" and have the semi-colon removed from the lines:
extension=php_mysql.dll
extension=php_mysqli.dll
[Additional information]
I found a test to run and according to phpinfo() it is not loading a configuration file:
Configuration File (php.ini) Path C:\Windows
Loaded Configuration File (none)
Scan this dir for additional .ini files (none)
Additional .ini files parsed (none)
For some reason, the PHPStorm web server is not looking for php.ini in the right place?
I have this setting in the "Interpreter options" per this:
--php-ini C:\PHP\php-5.6.7\php.ini
I have verified that this is the correct path.
scrowler and Michael Bush pointed out the answer in comments above. I thought I'd create an answer for it for the benefit of someone viewing the thread. Thanks, scrowler and Michael Bush.
The php.ini-development and php.ini-production files are templates. In order to have effect, one of them needs to be copied and renamed php.ini.
Have you added the PHP installation directory to you environment path
right click on my computer from the start menu
click on properties
find advanced system settings
click on environment variables
under system variables find PATH add C:\php replacing C:\php with your PHP
installation directory; *** remember the path separator
Also check this entry in your php.ini
; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
extension_dir = "c:/php/ext"

PHP: Fatal error: Class 'SoapClient' not found

First of all, I've read this question (Fatal error: Class 'SoapClient' not found) and have everything done the answer says. But still experience an issue.
I also found similar issue here (https://bugs.php.net/bug.php?id=64445) but it is not solved there too.
I'm trying to set up a PHP + Apache environment on Win 7 64.
PHP: php-5.5.17-Win32-VC11-x86. Thread safe.
Apache: httpd-2.4.10-win32-VC11
So, here is my C:\PHP\php.ini for SOAP. Everything is set correctly:
extension=php_soap.dll
; Directory in which the loadable extensions (modules) reside.
; On windows:
extension_dir = "C:/PHP/ext"
[soap]
; Enables or disables WSDL caching feature.
; http://php.net/soap.wsdl-cache-enabled
soap.wsdl_cache_enabled=1
; Sets the directory name where SOAP extension will put cache files.
; http://php.net/soap.wsdl-cache-dir
soap.wsdl_cache_dir="/tmp"
; (time to live) Sets the number of second while cached file will be used
; instead of original one.
; http://php.net/soap.wsdl-cache-ttl
soap.wsdl_cache_ttl=86400
; Sets the size of the cache limit. (Max. number of WSDL files to cache)
soap.wsdl_cache_limit = 5
In C:/PHP/ext folder I have php_soap.dll file, C:\PHP\ext\php_soap.dll.
But my phpinfo(); returns ONLY this about SOAP:
I DO NOT have these settings shown:
And I get error:
Fatal error: Class 'SoapClient' not found in C:\Apache24\htdocs\myApp\src\Em\Bundle\PlatformBundle\Services\MyAppService.php on line 46
What did I miss? How to solve it?
This is very easy.
You work with Symfony2 i think and you use namespaces. This function is in the Root-Namespace.
use:
\SoapClient()
Otherwise you are in the namespace and they can't find the class.
You have the same Problem with the Exception class for example.
If you are on linux and you are missing the soap extension, like I was and you have already enabled it in php.ini then try
apt-get install php-soap
service apache2 restart
I had the same issue in a custom module Drupal 8.
It uses Symfony2 so just add this in controller :
use SoapClient;
in PHP/7.4.11 Server
In XAMPP Control Panel
Stop Apache Server
Click on Config next to Apache
From dropdown select PHP (php.ini)
Ctrl+F to find ;extension=soap and remove ; from the line.
Ctrl+S to save the file.
Start Apache again.
this steps solved my problem.
Try config the extension using the path:
extension=ext/php_soap.dll
In phpinfo() you can see this important lines:
Configuration File (php.ini) Path C:\WINDOWS
Loaded Configuration File C:\Apache24\bin\php.ini
But you can change the ini folder if desire in httpd.conf:
# configure the path to php.ini
#PHPIniDir "C:/php"
BUT SEE what extension dir are you using:
extension_dir C:\php
In the "Core" section. This can be configured too.

How to enable mysqli on XAMPP?

By seeing suggestions throughout the Internet I tried to convert all my queries to mysqli.
But mysqli is not working in my XAMPP. I checked my PHP folder and there is a php_mysqli.dll file... still it doesn't work
Have you declare it to php.ini to load it? If no, try find this in php.ini and add php_mysqli.dll
;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;
; If you wish to have an extension loaded automatically, use the following
; syntax:
;
; extension=modulename.extension
;
; For example, on Windows:
;
; extension=msql.dll
;
; ... or under UNIX:
;
; extension=msql.so
;
; ... or with a path:
;
; extension=/path/to/extension/msql.so
;
; If you only provide the name of the extension, PHP will look for it in its
; default extension directory.
;
; Windows Extensions
; Note that ODBC support is built in, so no dll is needed for it.
; Note that many DLL files are located in the extensions/ (PHP 4) ext/ (PHP 5)
; extension folders as well as the separate PECL DLL download (PHP 5).
; Be sure to appropriately set the extension_dir directive.
extension= php_mysqli.dll
Goto the directory phpMyAdmin, find there is a file with name config.inc.php, open the file and find a line there as:
$cfg['Servers'][$i]['extension'] = 'mysql';
just change mysql to mysqli.
Another thing that might be blocking the msqli dll from loading could be user right issues on your local webserver, make sure the \User can read the ext folder, that was what worked for me
I think you should use XAMPP 1.8.3-1, XAMPP 1.8.2-2, XAMPP 1.8.1.
Because these xampp versions also support Mysqli by default.

Categories