I made a php webpage with login and password it used run on my previous system (xampp was ran database in that system) but after installed xampp in my system I started Apcahce and Mysql (running succesfully). The login page ran all fine but once i tried to login it s giving me this error
**could not find driver
Notice: Undefined variable: db in C:\xampp\htdocs\FINALschool\GLOBAL1.php on line 12
Fatal error: Call to a member function query() on null in C:\xampp\htdocs\FINALschool\GLOBAL1.php on line**
The on my link to db folder is
<?php
$dbName = $_SERVER["DOCUMENT_ROOT"] . "\FINALSCHOOL\REG.MDB";
if (!file_exists($dbName)) {
die("Could not find database file.");
}
try{
$db = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb)};Dbq=$dbName;Uid=Admin");
}
catch(PDOException $e){
echo $e->getMessage();
}
?>
I have also checked my user name and password for the login with my database and it is all the same so please help
Also my xampp is connected to it's default port
You can't just point to the .mdb file as a data source, you have to set up a MSAccess ODBC source:
Start at Start > Settings > Control Panel > Administrative Tools > Data Sources (ODBC)
Then for your $dbName you use the DSN you chose as the name of source (e.g. "IguanaTestData" below).
Reference
Related
I am fairly new to databases and also my English is very bad so don't mind my silly mistakes. I am using:
MS Access 2016 to create a local database named as tc.accdb
XAMPP to provide local host connectivity
this php code to check whether local connectivity is achieved or not:
<?php
$con = odbc_connect( "tc" , "" , "" );
if($con)
{
echo "Connected";
}
else
{
echo "Failed" ;
}
?>
But I just cannot set up Microsoft Access driver for my database. Under administrator tools >.....> System DSN, there exist Microsoft Access driver for (*.mdb) .But since I'm using Access 2016, my database has (.accdb) extension.
I've also tried saving my database as (database.mdb) to avoid extension confilicts but I've used some Office16-specific features so it can't be saved as a database with (.mdb) extension.
Note
Using (.mdb) connectivity with my (.accdb) database just didn't do the job as when I try to run the check code it gives me following error.
try this
$connStr = 'odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};' .
'Dbq=C:\\Users\\Igor\\Desktop\\example.accdb;';
$dbh = new PDO($connStr);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
good luck
I have created an intranet php site using WampServer on my home test environment where everything works fine. I then tried to install it on the production server, again with WampServer installed, but when I try to connect to the database, I get an error:
ERROR: SQL STATE[IM002] SQLDriverConnect:0 [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified.
I have the php_pdo_odbc extension enabled.
Here is the code I'm having trouble with:
$dbName2013 = $_SERVER["DOCUMENT_ROOT"] . "/Ridley/RLCompRepair.accdb";
try {
$db = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};;Dbq=$dbName2013");
}
catch (Exception $e) {
echo "ERROR: ".$e->getMessage();
}
Any and all help would be greatly appreciated.
Chris
You are trying to connect with DNS-less database.
create a Windows ODBC DNS
In Windows go to "Administrative Tools" and Select "Data Sources"
Go to File DSN select Add
select Microsoft Access Driver (*.mdb)
Select Next, type in a Data source Name
select "Next" then Finish
You should be in ODBC Microsoft Access Setup
select "Select" navigate to your .mdb and select it.
select "OK"
In your PHP try this:
$connect = odbc_connect("[data source name given]", "user", "password");
$connect = odbc_connect("myaccess", "", "");
if($connect === false){echo "did not work<br>";exit}
echo "success";
I used odbc_connect() in my PHP page to connect to the HANA database. It works fine when i run it locally.
I upload the same PHP page into the server and i am getting this error:
Fatal error: Call to undefined function odbc_connect()
The code:
$connect = odbc_connect("Team6DataSource", "TEAM6", "Password1", SQL_CUR_USE_ODBC);
Team6DataSource = datasource name.
ip address = 54.217.234.218
Can any one please help me?
Thanks
I just go through in google get this instruction this is really helpful for you.
Download the SQL Server ODBC driver for your PHP client
platform. (Registration required.) If the SQL Server ODBC driver
is not currently available for your platform, check the list of
ODBC-ODBC Bridge Client platforms. The ODBC-ODBC Bridge is an
alternative SQL Server solution from Easysoft, which you can
download from this site.
Install and license the SQL Server ODBC driver on the machine where
PHP is installed. For installation instructions, see the ODBC driver
documentation. Refer to the documentation to see which environment
variables you need to set (LD_LIBRARY_PATH, LIBPATH, LD_RUN_PATH,
SHLIB_PATH depending on the driver, platform and linker).
Create an ODBC data source in /etc/odbc.ini that connects to the
SQL Server database you want to access from PHP. For example, this
SQL Server ODBC data source connects to a SQL Server Express instance
that serves the Northwind database:
Use isql to test the new data source. For example:
cd /usr/local/easysoft/unixODBC/bin
./isql -v MSSQL-PHP
[MSSQL-PHP]
Driver = Easysoft ODBC-SQL Server
Server = my_machine\SQLEXPRESS
User = my_domain\my_user
Password = my_password
Please copy and paste this script and execute this
<?
/*
PHP MSSQL Example
Replace data_source_name with the name of your data source.
Replace database_username and database_password
with the SQL Server database username and password.
*/
$data_source='data_source_name';
$user='database_username';
$password='database_password';
// Connect to the data source and get a handle for that connection.
$conn=odbc_connect($data_source,$user,$password);
if (!$conn){
if (phpversion() < '4.0'){
exit("Connection Failed: . $php_errormsg" );
}
else{
exit("Connection Failed:" . odbc_errormsg() );
}
}
// This query generates a result set with one record in it.
$sql="SELECT 1 AS test_col";
# Execute the statement.
$rs=odbc_exec($conn,$sql);
// Fetch and display the result set value.
if (!$rs){
exit("Error in SQL");
}
while (odbc_fetch_row($rs)){
$col1=odbc_result($rs, "test_col");
echo "$col1\n";
}
// Disconnect the database from the database handle.
odbc_close($conn);
?>
Replace data_source_name, database_username and database_password
with your SQL Server ODBC data source, login name and password.
To run the script under Apache, save the file below your Apache web
server’s document root directory. For example,
/var/www/apache2-default/php-mssql-connection.phtml. Then view the
file in a web browser:
http://localhost/php-mssql-connection.phtml
If your web browser is not running on the same machine as the web
server, replace localhost with the web server’s host name or IP
address.
To run the script from the command line, save the file.
For example,
/tmp/php-mssql-connection.php. Then run $ php
/tmp/php-mssql-connection.php.
further more Details Refer this LINK
Download this, copy the .dll to PHP folder and in the php.ini file add:
extension=php_sqlsrv_7_ts_x64.dll
extension=php_pdo_sqlsrv_7_nts_x64.dll
i have site hosted on bluehost.com (Linux Server), i have use case that i have to Export some Specific Data Export to MS Access File,
I have following code to Connect with MS Access File:
$dbh = null;
try{
$dbh = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb)};Dbq=$file_path", $user_name, $password, $db_info);
}catch(PDOException $e){
echo $e->getMessage();
}
return $dbh;
But when i run the above code on Hosting server than i got error
SQLSTATE[IM002] SQLDriverConnect: 0 [unixODBC][Driver Manager]Data source name not found, and no default driver specified
Later after some searching i changed the code of DB connection to
try{
$conn = odbc_connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=$file_path", ACCESS_DB_USERNAME, ACCESS_DB_PASSWORD);
}catch(Exception $ex){
echo $ex->getMessage();
}
in above code i did not get any exception but $conn is NULL, both code snippet working fine on my local Windows machine,
Can you people help me in fixing issue?? i want to make connection and want to run INSERT INTO statement on MS Access DB.
The docs for odbc_connect say it returns one of two things.
An ODBC connection.
FALSE on error.
Your code should look for FALSE, not for an exception.
The docs also have examples of several different kinds of connections. But I think the chances that Bluehost installs Microsoft Access drivers on all their Linux servers are less than zero.
I installed WAMP, I have access database file in project folder, but don't have installed Access on my computer.
Can I read and update Access file with PHP even I don't have installed Access?
And what will be connection string to Access database file?
I really need help with this.
All you need is the PHP api for ODBC.
Here is the example from the docs itself:
<?php
// Microsoft SQL Server using the SQL Native Client 10.0 ODBC Driver - allows connection to SQL 7, 2000, 2005 and 2008
$connection = odbc_connect("Driver={SQL Server Native Client 10.0};Server=$server;Database=$database;", $user, $password);
// Microsoft Access
$connection = odbc_connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=$mdbFilename", $user, $password);
// Microsoft Excel
$excelFile = realpath('C:/ExcelData.xls');
$excelDir = dirname($excelFile);
$connection = odbc_connect("Driver={Microsoft Excel Driver (*.xls)};DriverId=790;Dbq=$excelFile;DefaultDir=$excelDir" , '', '');
?>
// Microsoft Access
Open the Administrative Tools icon in your Control Panel.
Double-click on the Data Sources (ODBC) icon inside.
Choose the System DSN tab.
Click on Add in the System DSN tab.
Select the Microsoft Access Driver.
Click Finish.
In the next screen, click Select to locate the database.
Give the database a Data Source Name (DSN).
Click OK.
$dsn='database.accdb';
$username='';
$password='';
$connect=odbc_connect($dsn, $username, $password);
I'v found this link with a tutorial on how to do it. Be careful that things work differently in windows and UNIX environment, but since you are using a WAMP you should have no problems
<?php
$db = $_SERVER["DOCUMENT_ROOT"] ."/AccessDatabase/reg.accdb"; //AccessDatabase is folder in htdocs where the database is store
if (!file_exists($db))
{
die("No database file.");
}
$dbNew = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb, *.accdb)}; DBQ=$db; Uid=; Pwd=;");
$sql = "select * from reg"; //reg is table name
$rs = $dbNew->query($sql);
while($result = $rs->fetch())
{
echo $result[0].": ".$result[1].": ".$result[2]."<br />";
}
?>
If u got error like pdo ODBC Drivers not installed
just go to php.ini and find extension = pdo_ODBC Driver and remove the comment(;)
after that restart the apache