I am attempting to install phpBugTracker on our web server. When I attempt to test the database connection on the installation screen, I get an error screen that reads "DB Test Failure... DB Error: extension not found". The error is being thrown from the following function:
function test_database(&$params, $testonly = false) {
// PEAR::DB
define('PEAR_PATH', ''); // Set this to '/some/path/' to not use system-wide PEAR
// define('PEAR_PATH', 'inc/pear/'); // use a locally installed Pear (phpBT v0.9.1)
if (!#include_once(PEAR_PATH.'DB.php')) {
$error_message = translate("Failed loading Pear:DB");
$error_info = translate("Please check your Pear installation and the defined PEAR_PATH in install.php");
$error_info .= " <a href='http://pear.php.net/'>http://pear.php.net/</a>";
include('templates/default/install-dbfailure.html');
exit;
}
// execution gets this far without a problem...
$dsn = array(
'phptype' => $params['db_type'],
'hostspec' => $params['db_host'],
'database' => $params['db_database'],
'username' => $params['db_user'],
'password' => $params['db_pass']
);
$db = DB::Connect($dsn);
// Simple error checking on returned DB object to check connection to db
if (DB::isError($db)) {
// $db go boom...
$error_message = isset($db->message) ? $db->message : '';
$error_info = isset($db->user_info) ? $db->user_info : '';
include('templates/default/install-dbfailure.html');
exit;
} else {
if ($testonly) {
include('templates/default/install-dbsuccess.html');
exit;
} else {
return $db;
}
}
}
I am using MySQL version 5.0.45, PHP version 4.47, and I have PEAR::DB version 1.7.6 stable. I've already verified that I can connect to the database I'm using with the login I've created otherwise. I am at the mercy of my hosting company as to what modules are installed.
Any ideas on what could be causing the error?
Edit: db_type is set to "mysqli". When I use "mysql" as the type I get a "connection failed" error instead.
Okay, I feel rather silly, but the path to MySQL was different on this particular server and I had just assumed localhost. This had nothing to do mysql vs. mysqli. Fixed path and it connected just fine.
Verify with phpinfo() that extension for db_type you're using is installed and activated.
Perhaps you're trying with "mysqli" db_type, while you should use "mysql"
(without 'i')?
MySQLi doesn't come by default with PHP4.
Related
I'm trying to set up the internal php server. When I run it I get the following message:
Fatal error: could not find driver in
E:\webProjects\skipper\drydockx\includes\functions.php on line 50
line 50 of the functions.php file: (at the bottom)
function query(/* $sql [, ... ] */)
{
// SQL statement
$sql = func_get_arg(0);
// parameters, if any
$parameters = array_slice(func_get_args(), 1);
// try to connect to database
static $handle;
if (!isset($handle))
{
try
{
// connect to database
$handle = new PDO("mysql:dbname=" . DATABASE . ";host=" . SERVER, USERNAME, PASSWORD);
// ensure that PDO::prepare returns false when passed invalid SQL
$handle->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
}
catch (Exception $e)
{
// trigger (big, orange) error
trigger_error($e->getMessage(), E_USER_ERROR); //LINE 50
exit;
}
}
You need to have a module called pdo_mysql. Looking for following in phpinfo()
pdo_mysql
PDO Driver for MySQL, client library version => 5.1.44
In Ubuntu/Debian you can use:
PHP5: sudo apt-get install php5-mysql
PHP7: sudo apt-get install php7.0-mysql
for Windows 8.1/10 in :\php.ini file you should uncomment line "extension=pdo_mysql"
hi friends ,
class MyDB extends SQLite3
{
function __construct()
{
$this->open('/var/cpanel/eximstats_db.sqlite3');
}
}
$db = new MyDB();
if(!$db){
echo $db->lastErrorMsg();
} else {
echo "Opened database successfully\n";
}
i have using eximstats db from server. while on updating my server the eximstats db get got under the SQLite3. i am new one to SQLite3 even though I have tried many more times access that db using the above php code but never i got result . please help me to improve this coding.
Is this code is correct . while running this i got "Fatal error: Uncaught exception 'Exception' with message 'Unable to open database: unable to open database file' "
thank you
You can simply use PHP PDO interface to access your SQLite3 database.
$db = new PDO('sqlite:/var/cpanel/eximstats_db.sqlite3')
PDO_SQLITE DSN
To access a database on disk, append the absolute path to the DSN prefix.
Just make sure that you have the PDO Driver for SQLite 3.x installed on your system.
Now to select a table just do:
$result = $db->query('SELECT * FROM tablename');
foreach( $result as $row ) {
print_r( $row );
}
I'm fairly new to MySQL and PHP, so bear with me. After some research, I found out...much to my distress...that apparently my site is hosted on a Windows server (by default) on GoDaddy which doesn't support PDO.
I just recently switched all database calls to use prepared statements through recommendation from another question I posted. I now find out that these aren't running and I'm getting a nasty error:
Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in D:\Hosting\8446415\html\ROOTFOLDER\php\Connect.php:8
Stack trace: #0 D:\Hosting\8446415\html\ROOTFOLDER\php\Connect.php(8): PDO->__construct('mysql:host=HOSTNAME', 'DBNAME', 'PASSWORD')
#1 D:\Hosting\8446415\html\ROOTFOLDER\admin.php(67): Connect->connect()
#2 {main} thrown in D:\Hosting\8446415\html\ROOTFOLDER\php\Connect.php on line 8
Here is Connect.php:
<?php
class Connect {
const expAddress = "HOSTNAME";
const expUser = "USERNAME";
const expPwd = "PASSWORD";
function connect() {
$db = new PDO('mysql:host='.self::expAddress.';dbname='.self::expUser.';charset=UTF-8', self::expUser, self::expPwd);
if(!$db) {
die("<p>Could not establish a connection to the database.</p>");
include('footer.php');
}
else {
return $db;
}
}
}
?>
So what is the fix here? I don't know what is supported, and I was told to shy away from all mysql_* statements.
I cannot upgrade my hosting account to Linux, even though that would be easiest. Do I need to use mysqli_* statements? How would this particular call change so that the input is safe from injection?
$stmt = $db->prepare("SELECT * FROM logins WHERE username=? AND password=?");
$stmt->execute(array($user, $pass));
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
You need to make sure you have pdo_mysql installed. Check phpinfo() for pdo_mysql ... if you know it's installed, you may just need to uncomment the extension=php_pdo_mysql.dll in php.ini ...
To catch your create error and display it nicely, you can modify your code as such:
try{
$db = new PDO('mysql:host='.self::expAddress.';dbname='.self::expUser.';charset=UTF-8', self::expUser, self::expPwd);
} catch (PDOException $e) {
die('Connect Failed: ' . $e->getMessage());
}
return $db;
If you do have access to php.ini, make sure that this line is uncommented:
extension_dir = "ext"
I'm working on a web application written with PHP and uses SQL Server 2008. To connect to database, I used SQLSRV driever of Microsoft. In a part of this application, I have to use SQL Transactions. As Microsoft suggested, I did it exactly based on this article. The main processes in my codes follow these steps:
1- starting sql transaction
2- send information to PHP files through jQuery and check the result sent by JSON
3- rollback if the result was false and go to the next query if it was true.
4- commit transactions if no error occurred and all results were ok.
// This is my pseudo code
if (sqlsrv_begin_transaction( $sqlsrv->sqlsrvLink ) === true) {
$firstQuery = sqlsrv_query($stmt1);
if (!$firstQuery) {
sqlsrv_rollback();
} else {
$nextQuery = sqlsrv_query($stmt2);
if (!$nextQuery) {
sqlsrv_rollback();
} else {
sqlsrv_commit();
}
}
} else {
print_r(sqlsrv_errors()); // Here is where I get the error below.
}
The problem I have is this error:
[Microsoft][SQL Server Native Client 10.0][SQL Server] New transaction is not allowed because there are other threads running in the session
I'm using SQLSRV driver ver.2.
What is this error for? How can I solve it?
I included the my own sqlsrv class to the first part of index.php containing the methods below:
function __construct($dbServerName,$dbUsername,$dbPassword,$dbName)
{
$connectionInfo = array("Database"=> $dbName, "CharacterSet" => "UTF-8");
$this->sqlsrvLink = sqlsrv_connect($dbServerName, $connectionInfo);
if ($this->sqlsrvLink === false) {
$this->sqlsrvError = sqlsrv_errors();
}
}
function __destruct()
{
sqlsrv_close($this->sqlsrvLink);
}
i think you should set MultipleActiveResultSets to true when you want to connect to sql server :
$conn = sqlsrv_connect('127.0.0.1', array
(
'Database' => 'Adventureworks',
'MultipleActiveResultSets' => true, // MARS ENABLED
));
http://php.net/manual/de/ref.pdo-sqlsrv.connection.php
From your error, It seems like $nextQuery = sqlsrv_query($stmt2); is starting a new transaction in the same session. Can you commit !$firstQuery before starting the second?
I have just changed the connection driver (extension) from mssql_connect to work with sqlsrv_connect. Unfortunately things do not seem to work as I wanted. I'd appreciate if someone can tell me what’s wrong and how can I fix it.
Code excerpt:
//a oracle DB moudle with a generic functions such as
//db_connect() db_query()
/// turn on verbose error reporting (15) to see all warnings and errors
error_reporting(15);
//generic DB operations
// Global record . for using in
$curr_rec = NULL;
function dbok($res)
{
if($res==false){
echo "DB error: "."FIXME need error mesg"."\n";
exit;
}
return $res;
}
function db_now_expr()
{
return "getdate()";
}
function db_is_connected($dbh)
{
return $dbh>0;
}
function ensure_connected($dbh)
{
if(!db_is_connected($dbh)) die("DB is not connected, operation failed");
//echo "DEBUG: hdb=$dbh";
}
//connect to given database
//return handler to DB
function dbo_logon($dbserver,$dbname)
{
$tsql = ??????? ====>>> what should i put here????
$dbserver = "computername\SQLEXPRESS";
$dbname = MY_Database_name;
$connectionOptions = array("Database"=>"BULL");
$dbh=dbok(sqlsrv_connect($dbserver, $connectionOptions));
dbok(sqlsrv_query($dbname,$dbh));
$stmt = sqlsrv_query( $connectionOptions, $tsql );
return $dbh;
}
//close DB
function dbo_logoff($dbh)
{
if(!db_is_connected($dbh)) echo("DB disconnect error");
sqlsrv_close($dbh);
}
Here is the original code using mssql_connect:
//a oracle DB module with a generic function such as
//db_connect() db_query()
/// turn on verbose error reporting (15) to see all warnings and errors
error_reporting(15);
//generic DB operations
// Global record . for using in
$curr_rec = NULL;
function dbok($res)
{
if($res==false){
echo "DB error: "."FIXME need error mesg"."\n";
exit;
}
return $res;
}
function db_now_expr()
{
return "getdate()";
}
function db_is_connected($dbh)
{
return $dbh>0;
}
function ensure_connected($dbh)
{
if(!db_is_connected($dbh)) die("DB is not connected, operation failed");
//echo "DEBUG: hdb=$dbh";
}
//connect to given database
//return handler to DB
function dbo_logon($dbserver,$dbuser,$dbpass,$dbname)
{
// $dbh=dbok(mssql_pconnect($dbserver,$dbuser,$dbpass));
$dbh=dbok(mssql_connect($dbserver,$dbuser,$dbpass));
//error_log("connect to [$dbname]".date("His")." \r\n",3,"/tmpbull.log"); //DBEUG DELME
dbok(mssql_select_db($dbname,$dbh));
//dbo_exec($dbh,"alter session set NLS_DATE_FORMAT='dd-mm-yyyy //hh24:mi:ss'");
return $dbh;
}
//close DB
function dbo_logoff($dbh)
{
if(!db_is_connected($dbh)) echo("DB disconnect error");
mssql_close($dbh);
}
Note that I had to change the authentication method from SQL authentication to Windows authentication because sqlsrv_connect uses Windows authentication instead of SQL authentication. Is that right?
I think these two links will help to understand Difference between mssql and sqlsrv
http://blogs.msdn.com/b/brian_swan/archive/2010/03/08/mssql-vs-sqlsrv-what-s-the-difference-part-1.aspx
http://blogs.msdn.com/b/brian_swan/archive/2010/03/10/mssql-vs-sqlsrv-what-s-the-difference-part-2.aspx
Though in short, to quote one of the articles:
The sqlsrv driver is built, maintained, and supported by Microsoft`
and
The mssql driver is a community-built driver.
I’m not sure how recently this driver was updated or maintained as an official PHP extension, but as of the release of PHP 5.3, it is no longer available with PECL. A quick internet search turns up a few places to download the mssql driver, but none of them that I’ve found indicate that the driver is being actively maintained.
Source: http://blogs.msdn.com/b/brian_swan/archive/2010/03/08/mssql-vs-sqlsrv-what-s-the-difference-part-1.aspx
As for your code sample, see below:
$dbserver = "computername\SQLEXPRESS";
$dbname = "BULL";
$connetion = dbo_logon($dbserver,$dbname);
function dbo_logon($dbserver,$dbname) {
$connectionOptions = array("Database"=>$dbname);
$dbh=sqlsrv_connect($dbserver, $connectionOptions);
if(!$dbh){
die("Error in Database connection");
return false;
}
return $dbh;
}
I think this will work for the connection.please note the code is not tested.
"The sqlsrv driver is built, maintained, and supported by Microsoft`" well right now Sep 2014, there is no official release to support php 5.6 last official release is from april 2012. MS style...