Php support database not enabled

Php – How to enable php extensions and database support

After spending some time in setting up a local sever in mac os, installing php5, and finally installing mysql I am still running on problems when trying to perform an drupal install.

When going to install.php the page shows the following

PHP extensions Disabled

Drupal requires you to enable the PHP extensions in the following list (see the system
requirements page for more information):
gd

Database support Disabled.

Your web server does not appear to support any common PDO database extensions. Check with
your hosting provider to see if they support PDO (PHP Data Objects) and offer any databases
that Drupal supports.

Any ideas on how to proceed with the installation?

php5 and php5-gd were installed via macports. mysql was installed via homebrew.

Best Solution

You need two more packages to pass through this error message:

php5-gd and php5-mysql.

So just install it and you’ll not get any error.

Note: You can replace php5-mysql to other package based on the database you are using.

php5-sqlite for sqlite php5-pgsql for postgres php5-adodb for ADOdb database 
Php – How to prevent SQL injection in PHP

The correct way to avoid SQL injection attacks, no matter which database you use, is to separate the data from SQL, so that data stays data and will never be interpreted as commands by the SQL parser. It is possible to create SQL statement with correctly formatted data parts, but if you don’t fully understand the details, you should always use prepared statements and parameterized queries. These are SQL statements that are sent to and parsed by the database server separately from any parameters. This way it is impossible for an attacker to inject malicious SQL.

You basically have two options to achieve this:

    Using PDO (for any supported database driver):

 $stmt = $pdo->prepare('SELECT * FROM employees WHERE name = :name'); $stmt->execute([ 'name' => $name ]); foreach ($stmt as $row) < // Do something with $row >
 $stmt = $dbConnection->prepare('SELECT * FROM employees WHERE name = ?'); $stmt->bind_param('s', $name); // 's' specifies the variable type => 'string' $stmt->execute(); $result = $stmt->get_result(); while ($row = $result->fetch_assoc()) < // Do something with $row >

If you’re connecting to a database other than MySQL, there is a driver-specific second option that you can refer to (for example, pg_prepare() and pg_execute() for PostgreSQL). PDO is the universal option.

Читайте также:  Order system php mysql

Correctly setting up the connection

Note that when using PDO to access a MySQL database real prepared statements are not used by default. To fix this you have to disable the emulation of prepared statements. An example of creating a connection using PDO is:

$dbConnection = new PDO('mysql:dbname=dbtest;host=127.0.0.1;charset=utf8', 'user', 'password'); $dbConnection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $dbConnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 

In the above example the error mode isn’t strictly necessary, but it is advised to add it. This way the script will not stop with a Fatal Error when something goes wrong. And it gives the developer the chance to catch any error(s) which are throw n as PDOException s.

What is mandatory, however, is the first setAttribute() line, which tells PDO to disable emulated prepared statements and use real prepared statements. This makes sure the statement and the values aren’t parsed by PHP before sending it to the MySQL server (giving a possible attacker no chance to inject malicious SQL).

Although you can set the charset in the options of the constructor, it’s important to note that ‘older’ versions of PHP (before 5.3.6) silently ignored the charset parameter in the DSN.

Explanation

The SQL statement you pass to prepare is parsed and compiled by the database server. By specifying parameters (either a ? or a named parameter like :name in the example above) you tell the database engine where you want to filter on. Then when you call execute , the prepared statement is combined with the parameter values you specify.

The important thing here is that the parameter values are combined with the compiled statement, not an SQL string. SQL injection works by tricking the script into including malicious strings when it creates SQL to send to the database. So by sending the actual SQL separately from the parameters, you limit the risk of ending up with something you didn’t intend.

Any parameters you send when using a prepared statement will just be treated as strings (although the database engine may do some optimization so parameters may end up as numbers too, of course). In the example above, if the $name variable contains ‘Sarah’; DELETE FROM employees the result would simply be a search for the string «‘Sarah’; DELETE FROM employees» , and you will not end up with an empty table.

Another benefit of using prepared statements is that if you execute the same statement many times in the same session it will only be parsed and compiled once, giving you some speed gains.

Oh, and since you asked about how to do it for an insert, here’s an example (using PDO):

$preparedStatement = $db->prepare('INSERT INTO table (column) VALUES (:column)'); $preparedStatement->execute([ 'column' => $unsafeValue ]); 

Can prepared statements be used for dynamic queries?

While you can still use prepared statements for the query parameters, the structure of the dynamic query itself cannot be parametrized and certain query features cannot be parametrized.

Читайте также:  Как сделать пункты html

For these specific scenarios, the best thing to do is use a whitelist filter that restricts the possible values.

// Value whitelist // $dir can only be 'DESC', otherwise it will be 'ASC' if (empty($dir) || $dir !== 'DESC')
Python – How to connect to a MySQL Database in Python

Connecting to MYSQL with Python 2 in three steps

You must install a MySQL driver before doing anything. Unlike PHP, Only the SQLite driver is installed by default with Python. The most used package to do so is MySQLdb but it’s hard to install it using easy_install. Please note MySQLdb only supports Python 2.

For Windows user, you can get an exe of MySQLdb.

For Linux, this is a casual package (python-mysqldb). (You can use sudo apt-get install python-mysqldb (for debian based distros), yum install MySQL-python (for rpm-based), or dnf install python-mysql (for modern fedora distro) in command line to download.)

After installing, Reboot. This is not mandatory, But it will prevent me from answering 3 or 4 other questions in this post if something goes wrong. So please reboot.

Then it is just like using any other package :

#!/usr/bin/python import MySQLdb db = MySQLdb.connect(host="localhost", # your host, usually localhost user="john", # your username passwd="megajonhy", # your password db="jonhydb") # name of the data base # you must create a Cursor object. It will let # you execute all the queries you need cur = db.cursor() # Use all the SQL you like cur.execute("SELECT * FROM YOUR_TABLE_NAME") # print all the first cell of all the rows for row in cur.fetchall(): print row[0] db.close() 

Of course, there are thousand of possibilities and options; this is a very basic example. You will have to look at the documentation. A good starting point.

3 — More advanced usage

Once you know how it works, You may want to use an ORM to avoid writing SQL manually and manipulate your tables as they were Python objects. The most famous ORM in the Python community is SQLAlchemy.

I strongly advise you to use it: your life is going to be much easier.

I recently discovered another jewel in the Python world: peewee. It’s a very lite ORM, really easy and fast to setup then use. It makes my day for small projects or stand alone apps, Where using big tools like SQLAlchemy or Django is overkill :

import peewee from peewee import * db = MySQLDatabase('jonhydb', user='john', passwd='megajonhy') class Book(peewee.Model): author = peewee.CharField() title = peewee.TextField() class Meta: database = db Book.create_table() book = Book(author="me", title='Peewee is cool') book.save() for book in Book.filter(author="me"): print book.title 

This example works out of the box. Nothing other than having peewee ( pip install peewee ) is required.

Источник

Mantis Bug Tracker — Forums

Database connection failed. Error received from database was #0: PHP Support for database is not enabled.

Database connection failed. Error received from database was #0: PHP Support for database is not enabled.

Post by sentinel » 17 Sep 2018, 05:41

Читайте также:  Php номер месяца и года

We are having an issue with our MantisBT from this weekend and hoping some one could help. We’re not quite sure if there something has changed by the hosting provider (Upgrade of the server or php mysql) but when we try to load the mantis, we get error: Database connection failed. Error received from database was #0: PHP Support for database is not enabled. (screenshot attached)

We tried to modify configuration using the following link

After changing $g_db_type = ‘mysql’; to $g_db_type = ‘mysqli’; there is no error message but also the web page is blank with nothing in it.

The version of Mantis we are using is very old: Mantis 125, Database version 183

atrol Site Admin Posts: 8208 Joined: 26 Mar 2008, 21:37 Location: Germany

Re: Database connection failed. Error received from database was #0: PHP Support for database is not enabled.

Post by atrol » 17 Sep 2018, 07:26

Maybe your provider changed your PHP version to a newer one (>= 7.0).
Maybe there is a setting where you can change it back.

If not, you have to upgrade Mantis, as Mantis 1.2.5 does not support latest PHP versions.

Re: Database connection failed. Error received from database was #0: PHP Support for database is not enabled.

Post by sentinel » 21 Sep 2018, 05:48

Thanks mate for the reply, actually the hosting provided did upgrade to 7.0. We upgraded Mantis to 270 and now it is up again!

  • MantisBT — English
  • ↳ Announcements
  • ↳ General Discussion
  • ↳ Help
  • ↳ Customizations
  • ↳ Plugins
  • ↳ General Plugin Discussion
  • ↳ EmailReporting
  • ↳ Mylyn Connector
  • MantisBT — International
  • ↳ Deutsch
  • ↳ French
  • ↳ Russian

Powered by phpBB® Forum Software © phpBB Limited

Источник

Php support database not enabled

When upgrading from 2.6.0 -> 2.7.0, I now get a fatal error page when loading the main index.php:

APPLICATION ERROR #400
Database connection failed. Error received from database was #0: PHP Support for database is not enabled.

If I look at the admin/install.php page, I see:
Checking PHP support for database type BAD
database is not supported by PHP. Check that it has been compiled into your server.
Checking PHP support for MySQL driver BAD
mysql driver is deprecated as of PHP 5.5.0, and has been removed as of PHP 7.0.0. The driver is no longer supported by MantisBT, please use mysqli instead

Version 2.6.0 works perfectly in this environment. Version 2.7.0 does not.

Enviroment is EL7 with Remi’s PHP 7.0 packages:
$ rpm -qa | grep remi | sort
gd-last-2.2.5-1.el7.remi.x86_64
libzip5-1.3.0-1.el7.remi.x86_64
libzip-last-1.1.3-1.el7.remi.x86_64
php-7.0.24-1.el7.remi.x86_64
php-cli-7.0.24-1.el7.remi.x86_64
php-common-7.0.24-1.el7.remi.x86_64
php-gd-7.0.24-1.el7.remi.x86_64
php-intl-7.0.24-1.el7.remi.x86_64
php-json-7.0.24-1.el7.remi.x86_64
php-mbstring-7.0.24-1.el7.remi.x86_64
php-mysqlnd-7.0.24-1.el7.remi.x86_64
php-opcache-7.0.24-1.el7.remi.x86_64
php-pdo-7.0.24-1.el7.remi.x86_64
php-pecl-apcu-5.1.8-1.el7.remi.7.0.x86_64
php-pecl-apcu-bc-1.0.3-1.el7.remi.7.0.x86_64
php-pecl-memcache-3.0.9-0.9.20170802.e702b5f.el7.remi.7.0.x86_64
php-pecl-mysql-1.0.0-0.9.20151007git294ce3b.el7.remi.7.0.x86_64
php-pecl-zip-1.15.1-1.el7.remi.7.0.x86_64
php-process-7.0.24-1.el7.remi.x86_64
php-xml-7.0.24-1.el7.remi.x86_64
remi-release-7.3-2.el7.remi.noarch

Источник

Оцените статью