I am little bit confused with strange behavior of PHP and need advice how to fix it.
I am tring to test pretty simple php script:
$conn = oci_connect($dbUser, $dbPassword, $dbServerName . "/" . $dbName);
if (!$conn) {
$e = oci_error();
trigger_error(htmlentities($e['message']), E_USER_ERROR);
}
Unfortunatly it raise me next ERROR:
[22-Oct-2018 19:22:23] PHP Warning: PHP Startup: Unable to load dynamic library 'F:\PHP_x64\ext\php_oci8_12c.dll' - The specified procedure could not be found.
in Unknown on line 0
[22-Oct-2018 19:22:23] PHP Fatal error: Call to undefined function oci_connect() in F:\TEST\complain\test.php on line 8
I have project which is located in IIS web server. Project use PHP Version 5.6.28.
Inside F:\PHP_x64\ext\ folder I have file php_oci8_12c.dll as you can see below:
Inside php.ini file I have uncommented line:
extension=php_oci8_12c.dll
Also in php.ini file I add:
extension_dir = "F:\PHP_x64\ext\"
[PHP_OCI8_12C]
extension=php_oci8_12c.dll
I restart IIS web server several times.
When I try to call php.exe from console it show me next error:
Finally I found solution which work for me.
The code which I use to connect PHP with Oracle:
$conn = oci_connect($dbUser, $dbPassword, "(DESCRIPTION=(ADDRESS_LIST =(ADDRESS=(PROTOCOL = TCP)(HOST=$dbServerName)(PORT = 1521)))(CONNECT_DATA=(SID=$dbSID)))", 'AL32UTF8') or die("Could not connect to ORACLE");
In my case I used SID, you can also use SERVICE_NAME.
Related
Trying to connect php to oracle 19c, using php 8.1, apache lounge, this is the code i am trying to run
// Create connection
$conn = oci_connect($username, $password, $servername);
// Check connection
if (!$conn) {
$e = oci_error();
echo htmlentities($e["message"]);
}
error message: Warning: oci_connect(): ORA-12637: Packet receive failed
I have download and set the enviroment variable of both the latest oracle instant client and the version 19_15. But still getting the same error message have also uncommented the dll files oci8_19 and pdo_oci.
I'm trying to setup a new local web server. Apache is already running and php is working. Mysql is installed. I can run mysql through the MySQL workbench. However, I am not able to connect to the MySQL from the php document.
First, the guides I looked at said to add the extension in php.ini. I went to php.ini-development and uncommented the line:
extension=mysqli
After restarting the server this didn't help. I also tried variations like extension=php_mysqli, and php_mysqli.dll.
I do in fact have the mysql dll on my computer. It is in:
C:\php\ext\php_mysqli.dll
My computer says the dll has not been accessed or modified since I downloaded it, so the Apache hasn't touched it at all.
Here is the code:
<?
$servername = "localhost";
$username = "root";
$password = "*************";
$conn = new mysqli($servername, $username, $password);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
I get this error:
Fatal error: Uncaught Error: Class 'mysqli' not found in C:\Websites\x.php:14 Stack trace: #0 {main} thrown in C:\Websites\x.php on line 14
The MySQL is set to port 3306, and mysqli.default_port is set to 3306 in httpd.conf.
This is Windows 10. The MySQL version is 8.0.2. How can I make PHP use the mysql library/talk to MySQL?
EDIT:
Not the same as How to solve "Fatal error: Class 'MySQLi' not found"?.
I have tried the solutions there, but none of the answers worked so far.
First, be sure you're editing the "right" php.ini file. There can be several php.ini files on your system so execute this PHP code to see which php.ini is loaded in the context of your database connection script:
var_dump(php_ini_loaded_file());
Then, try to specify in this php.ini the absolute path to MySQLi DLL file like this:
extension=C:\php\ext\php_mysqli.dll
Note: Don't forget to restart Apache server after the modification of the php.ini.
I'm using wamp64 as localhost for programming my php code.
But now I got asked to connect to a MSSQL DB.
I searched for answers on how to do it and found sqlsrv_connect() function.
When I call this function I get this error:
Uncaught Error: Call to undefined function sqlsrv_connect() in C:\wamp64\
I'm not familiar with this, so could someone help me with instructions on how to fix this?
I also read that I need to install!? (I don't understand how to do this)
My PHP version is 7.2.4
This is my code:
$serverName = "server, 1433"; //serverName\instanceName, portNumber
$connectionInfo = array( "Database"=>"DB", "UID"=>"USERNAME", "PWD"=>"PASSWORD");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
echo "Connection established.<br />";
}else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
I also downloaded some EXE files:
SQLSRV30.EXE, SQLSRV31.EXE, SQLSRV32.EXE, SQLSRV40.EXE
What do they mean? Which one should I have?
Please someone help me with this.
Edit: After trying the answer, I got this error:
PHP Startup: Unable to load dynamic library 'sqlsrv_72_nts'
I solved it ~ PHP Version 7.2.4
pdo_sqlsrv : 5.3.0+11108
1.download the proper version sqlsrv and sqlsrv pdo
2.put it into XAMPP\PHP\ext folder
3.after that write the line into php.ini > module setting
extension=php_pdo_sqlsrv_72_ts.dll
extension=php_sqlsrv_72_ts.dll
4.let's make a test for MSSQL still there is an error msg for recommending you to download ODBC Driver for SQL
Go to https://learn.microsoft.com/zh-tw/sql/connect/odbc/download-odbc-driver-for-sql-server?view=sql-server-2017 then download the proper file
(mine is Command Line Utilities 11 for SQL ServerĀ® X86)
6.fire the test.php again everything works!
I followed #SayedMohdAli's steps and Got this error:
PHP Startup: Unable to load dynamic library 'sqlsrv_72_nts'
I changed the name from 'sqlsrv_72_nts' to 'sqlsrv_72_ts' and It worked.
#SayedMohdAli thanks for helping me with this getting started. Solved it with your help.
I'm attempting to connect with a Sybase database with PHP7 on Windows Server 2012 R2 using the sqlsrv PDO driver. I've tried a number of connection strings - the following is the most direct connection string I've found that should be at least tossing me an error (an error from PHP) when accessing the page. However, when I access the page it it tells me the page is not working (as in the PHP is not working). PDO SQLSRV is active in my phpinfo(). The PHP Error I receive is:
[18-Nov-2016 22:32:18 UTC] PHP Warning: PHP Startup: Unable to load dynamic library 'C:\Program Files\PHP\v7.0\ext\php_wincache.dll' - The specified module could not be found.
in Unknown on line 0
And many times in the same log file I am receiving the following error:
[18-Nov-2016 22:31:23 UTC] PHP Warning: PHP Startup: Unable to load dynamic library 'C:\Program Files\PHP\v7.0\ext\php_mysql.dll' - The specified module could not be found.
in Unknown on line 0
This is all basically a straight-up install, so I'm surprised that it's tossing back errors about windows cache and mysql (when I'm not even attempting to access a mysql anything). Any leads or information would be great. Thank you for this forum!
<?php
try {
$server_name = "MY\SERVER,1234";
$database_name = "myDatabase";
$username = "myUsername";
$password = "myPassword";
$conn = new PDO("sqlsrv:server=$server_name;database=$database_name", "$username", "$password");
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
}
catch( PDOException $e ) {
die( "Error connecting to SQL Server" );
}
echo "Connected to SQL Server\n";
?>
I have a php file(conn.php) which has the following contents:
<?php
$conn = oci_connect('mdl_img_tst', 'mdl_tst_usr', 'draa.uofl.com');
if (!$conn) {
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
?>
Running this from the command line it returns following two errors:
Failed loading /usr/lib/php/extensions/no-debug-non-zts-20090626/5.3/xdebug.so: dlopen(/usr/lib/php/extensions/no-debug-non-zts-20090626/5.3/xdebug.so, 9): image not found
PHP Fatal error: Call to undefined function oci_connect() in /Users/crdc/Sites/conn.php on line 5
What could be the possible reason for that?
UPDATE: I added a line extension=oci8.so and now there is a different error. Now it seems like oci8 is installed correctly but it has some problem with connection string.
PHP Warning: oci_connect(): ORA-12504: TNS:listener was not given the SERVICE_NAME in CONNECT_DATA in /Users/crdc/Sites/conn.php on line 5
PHP Fatal error: ORA-12504: TNS:listener was not given the SERVICE_NAME in CONNECT_DATA in /Users/crdc/Sites/conn.php on line 8
Any idea on that?
I would recommend verifying that OCI8 has actually been loaded by PHP.
Run this script
<?php
phpinfo();
?>
And verify that OCI8 is shown as a loaded plugin.