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');"
Related
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
I'm trying to connect to a Foxpro database using the OLE DB Driver
I downloaded the driver from http://www.microsoft.com/en-us/download/details.aspx?id=14839 and installed it then create a php script
$conn = new COM("ADODB.Connection") or die("Cannot start ADO");
$conn->Open("Provider=vfpoledb.1;Data Source=C:\Opera3\Comp_I.DBC;Collating Sequence=machine");
This gives me the following error
Fatal error: Uncaught exception 'com_exception' with message '<b>Source:</b> ADODB.Connection<br/><b>Description:</b> Provider cannot be found. It may not be properly installed.' in C:\inetpub\wwwroot\test1.php:4 Stack trace: #0 C:\inetpub\wwwroot\test1.php(4): com->Open('Provider=vfpole...') #1 {main} thrown in C:\inetpub\wwwroot\test1.php on line 4
Any help in getting this working would be much appreciated.
As requested
uninstalled and reinstalled from command line as administrator for all users and now it works –
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.
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!
i have PHP Version 5.2.8 on my windows 2003 server, i am trying to connect with database
$dbh = new PDO("mysql:host=localhost;port=3306;dbname=$db_name", $db_user, $db_pass);
but when i use this statement i got following error
Fatal error: Uncaught exception 'PDOException' with message 'could not find driver'
in bin\db.php:14 Stack trace: #0 bin\db.php(14):
PDO->__construct('mysql:host=loca...', 'root', '123') #1
main.php(4): include_once('C:\Inetpub\wwwr...') #2
{main} thrown in bin\db.php on line 14
how can i fix this problem?
Thanks
You must remove the ; on this line in php.ini :
;extension=php_pdo_mysql.dll
extension=php_pdo_mysql.dll
If you're upgrading PHP, be sure to check your environment variable information, especially your `PATH, and reboot if you change it.
I was using a php.ini file from a different directory. As Sebastian Grignoli suggests, check your phpinfo() results for the location of the php.ini it's using.