I have successfully loaded the sqlsrv_pdo_54 driver that is right for me with ts and vc9 and php 5.4 which I am running, and it shows up in phpmyinfo. I have downloaded the windows native client, switched my port to 8080, and have wamp 32 bit running on my computer. However, whenever I run the following script
<?php
require_once 'trunk\global.inc.php';
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if($conn === false)
{
die(print_r(sqlsrv_errors(), true));
}
?>
I get the following error message:
Fatal error: Call to undefined function sqlsrv_connect() in C:\wamp\www\test.php on line 11
Apparently the function is still undefined. Why is this happening when the driver has been loaded? I tried restarting my server and it did not work.
sqlsrv_pdo doesn't use the standard sqlsrv_* functions. It uses PDO. Try changing your code to use PDO.
<?php
require_once 'trunk\global.inc.php';
$conn = new PDO("sqlsrv:Server=MY_SERVER;Database=MY_DATABASE", MY_USERNAME, MY_PASSWORD);
if($conn === false)
{
die('Unable to connect to DB');
}
?>
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.
Hello I am a newbie in PHP and Oracle and I have to connect PHP to Oracle database on two different machines.
Here is my code:
<?php
$servername = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=aaa.bbb.ccc)
(PORT=1632))(CONNECT_DATA=(SERVER=dedicated)(SERVICE_NAME=int)))";
$conn = oci_connect("aaa", "bbb", $servername);
if (!$conn) {
$m = oci_error();
echo $m['message'], "\n";
exit;
}
else {
print "Connected to Oracle!";
}
// Close the Oracle connection
oci_close($conn);
?>
The error that i get is: Fatal error: Uncaught Error: Call to undefined function oci_connect() in C:\xampp\htdocs\php-e\serial.php:4 Stack trace: #0 {main} thrown in C:\xampp\htdocs\php-efactura\serial.php on line 4
I have read online that I have to decomment the extension=oci8_12c ; Use with Oracle Database 12c Instant Client which I did and install Oracle Instant Client 12 32 bit and add it to the path of the environment variables which I did. I even restarted the PC and it still gives me the same error. Do you have any ideea why id doesn`t work ? I am working from XAMPP.
Thanks in advance
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 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.
I wrote code as below:
<?php
$conn = mssql_connect("xx.xx.xx.xx", "username", "password")
or die("Can't connect to server ".mssql_error());
echo "Success";
mssql_close($conn);
?>
The error is:
PHP Warning: mssql_connect()
[function.mssql-connect]: Unable to
connect to server: xx.xx.xx.xx in
xxxxxxx\conn.php
on line 2 PHP Fatal error: Call to
undefined function mssql_error() in
xxxxxxx\conn.php
on line 3
The server is Apache2.2, the version of Sql Server is 2005, the version of PHP is 5.2.5, and I remove the ; before extension=php_mssql.dll and there is a php_mssql.dll in the ext directory
Could you check your apache log if there is a problem with the mssql extension when the service starts?
Use mssql_get_last_message()
<?php
$conn = mssql_connect("xx.xx.xx.xx", "username", "password")
or die("Can't connect to server ".mssql_get_last_message());
echo "Success";
mssql_close($conn);
?>