Connecting to SQL Server with PDO_MSSQL in PHP - php

I have a problem while trying to connect to my SQL Server 2000 database using pdo_mssql with this line:
$connection = new PDO ('mssql:host=localhost;dbname=DNAME', 'user', 'password');
The exception is the following:
PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] General SQL Server error: Check messages from the SQL Server. (severity 5)' in C:\Inetpub\wwwroot\public\test.php:2 Stack trace: #0 C:\Inetpub\wwwroot\public\test.php(2): PDO->__construct('mssql:host=loca...', 'user', 'password') #1 {main} thrown in C:\Inetpub\wwwroot\public\test.php on line 2
If I make the connection using the function mssql_connect() as follows, I obtain no error and my connection is correctly made:
$link = mssql_connect ('localhost', 'user', 'password');
Any idea? Where can I read the detailed error message? Thanks

My database name had the character "-", removing it solved the problem!

Related

Can't connect to odbc in php. could not find drivers

im trying to connect to a database on odbc with php and i get the error of
Fatal error: Uncaught PDOException: could not find driver in C:\xampp\htdocs\testarsybase\index.php:3 Stack trace: #0 C:\xampp\htdocs\testarsybase\index.php(3): PDO->__construct('odbc:host=192.1...', 'sa', '') #1 {main} thrown in C:\xampp\htdocs\testarsybase\index.php on line 3
im using the PDO('odbc (..)') to connect
What should i do?
See if this situation helps you. It seems to be the same question.
PDO returning error “could not find driver” with a known working DSN

Fatal error: Uncaught PDOException: SQLSTATE[HY000] [2019] Unknown character set

I am trying to learn about PDOs so I can migrate away from using mysqli functions but I can't seem to get the DSN right when connecting to the database. I don't know what charset to use. Is it something that I determine in phpmyadmin or is it something that is already set and I have to find? Not sure.
I have a MySQL database set up on a XAMPP program that I am trying to connect to. Below is my code from my db.php file and the full error message.
// CREATE PDO OBJECT WITH CONSTRUCTOR
$db = new PDO('mysql:host=localhost;dbname=phpdemo;charset=utf8', 'root', '');
// SET ATTRIBUTE RELATED TO ERROR HANDLING FOR SECURITY
$db -> setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$fb -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
Fatal error: Uncaught PDOException: SQLSTATE[HY000] [2019] Unknown character set in C:\xampp\htdocs\PHP\PDO Lab\includes\db.php:3 Stack trace: #0 C:\xampp\htdocs\PHP\PDO Lab\includes\db.php(3): PDO->__construct('mysql:host=loca...', 'root', '') #1 C:\xampp\htdocs\PHP\PDO Lab\includes\header.php(6): include_once('C:\xampp\htdocs...') #2 C:\xampp\htdocs\PHP\PDO Lab\new_user.php(2): include_once('C:\xampp\htdocs...') #3 {main} thrown in C:\xampp\htdocs\PHP\PDO Lab\includes\db.php on line 3
Edit: I have tried using utf8mb4 which results in the same error.
Edit2: I just realized that I don't get any errors when I open my db.php file. I do get errors when I open my new_user.php file who's only code is "include('db.php');"

Error when using PDO

So I just finally installed the PDO drivers, and now I have another issue. When I try to use
<?php
$username = "root";
$password = "allen123";
$conn = new PDO('mysql:host=localhost;dbname=test', $username, $password);
?>
Just to connect to the DB, I get the following error
Fatal error: Uncaught exception 'PDOException' with message
'SQLSTATE[HY000] [2002] No such file or directory' in
/Users/idrisk/Colourity/site/index.php:4 Stack trace: #0
/Users/idrisk/Colourity/site/index.php(4):
PDO->__construct('mysql:host=loca...', 'root', 'allen123') #1 {main}
thrown in /Users/idrisk/Colourity/site/index.php on line 4
I've looked at other posts on SO about this issue, but they all seem different. Any ideas?
EDIT
So I installed the drivers via Macports and this is what I get once It was installed
To use mysqlnd with a local MySQL server, edit /opt/local/etc/php55/php.ini and set mysql.default_socket, mysqli.default_socket and pdo_mysql.default_socket to the path
to your MySQL server's socket file.
For mysql51, use /opt/local/var/run/mysql51/mysqld.sock
For mysql55, use /opt/local/var/run/mysql55/mysqld.sock
For mysql56, use /opt/local/var/run/mysql56/mysqld.sock
For mariadb, use /opt/local/var/run/mariadb/mysqld.sock
For percona, use /opt/local/var/run/percona/mysqld.sock`
The other answers say to use something else.

PDO Cannot Connect to Remote MySQL

I've recently setup a load balancer, it has 3 public servers serving users.
Here's where I have my problem... the site uses PDO to connect to database, the MySQL server is on one single remote server for all them to connect to and it doesn't seem to work.
Here's the error I get:
"Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in /var/www/pingrglobe.com/backend/database.php:8 Stack trace: #0 /var/www/pingrglobe.com/backend/database.php(8): PDO->__construct('mysql:host=162....', 'root', 'nope') #1 /var/www/pingrglobe.com/structure/header.php(4): require('/var/www/pingrg...') #2 /var/www/pingrglobe.com/index.php(2): require('/var/www/pingrg...') #3 {main} thrown in /var/www/pingrglobe.com/backend/database.php on line 8"
Here's my code:
$host = "162.243.135.167";
$user = "root";
$pass = "nope;)";
$dbname = "pingrglobe";
$db = new PDO("mysql:host=".$host.";port=3306;dbname=".$dbname, $user, $pass);

PDO Informix SQLDriverConnect: -"917"

i have big problem while connection to a remote informix database server.
here's the code
$db = new PDO("informix:host=192.168.*.*; service=1565;
database=daten; server=name; protocol=onsoctcp;
EnableScrollableCursors=1", "informix", "info00");
print "Connection Established!\n\n";
echo "Table contents: $rows.\n";
I receive the following error:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE=HY000, SQLDriverConnect: -917 [Informix][Informix ODBC Driver][Informix]Must close current database before using a new database.' in /var/www/informix.php:9 Stack trace: #0 /var/www/informix.php(9): PDO->__construct('informix:host=1...', 'informix', 'info00') #1 {main} thrown in /var/www/informix.php on line 9
How can I fix this?
I think you should also set the DB_LOCALE environment variable.
When the client application requests a connection, it sends information, including the DB_LOCALE to the database server.

Categories