Call to undefined function odbc_connect() message while connecting SAP Hana database
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 theSQL 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
- Use isql to test the new data source. For example:
[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
undefined function odbc_connect() in PHP 7.2
The screenshot you've given does indeed show an ODBC driver installed. However, the driver in question is not the one that provides the odbc_xxx()
functions. Rather, it is the one that provides access to ODBC via the PDO library.
You have two options:
Install the ODBC driver extension for PHP that you need in order to get access to the
odbc_xxx()
functions. The exact method for doing this will vary according to your platform so I can't give exact instructions, but you will need administrator access to the server so it may or may not be a viable solution for you.Change your code to use the PDO library instead of the
odbc_xxx()
functions. You will need to connect to the DB using a line of code something like this:$db = new PDO('odbc:Server=dbIpAddr,portNumber;Database=databaseName', 'username', 'password');
... and then use PDO method calls from there on throughout your code to access the DB. Per your example, it would be something like this:
$stmt = $db->query("SELECT * FROM SalesOrders LIMIT 1");
while ($row = $stmt->fetch())
{
$json1[] = array_map('utf8_encode', $row);
}If you've already written all your code, this may be a pain. On the other hand, the good thing about doing it this way is that your code will be more portable between database engines, should you wish to do that. (there would still be work involved in doing so, as SQL is not a consistent language, but it would be possible to do)
Error in Connecting SAP HANA from PHP
Well, if you said you had a successful insert previously, it means the connection string works fine. The only issue I can see here is your server is no longer running. Cloudshare suspends the server every 60 mins (can be extended to 180), and your error message sounds exactly that.
ODBC connection on a wordpress site
$connect
will never be true. This is because odbc_connect()
does not return a boolean when it succeeds. It returns a connection ID
instead.
If the connection fails it will return an error or false
, so it will end up in the else
. If it succeeds it contains an ID
and should evaluate to true
.
if ($connect){
echo '<br> connected <br>';
} else{
echo '<br> not connected <br>';
}
Edit:
You've just added the error message you're getting. That error means the function
is not available, and that will most likely be caused by the missing ODBC drivers
for your php client. Someone else made this post on how to install this:
Call to undefined function odbc_connect() message while connecting SAP Hana database
I hope this helps.
Insert data in SQL Server database from excel using HTTP Post
Just change the POST to
"http://localhost:11121/Student/Insert/" + id
and then map the route
routes.MapRoute(
"InsertStudent",
"Student/Insert/{id}",
new { controller = "Student", action = "Insert", id = "" }
);
and then in your controller you can check if id is empty, if not then make a new user
also, sometimes I do things like this
routes.MapRoute(
"Resource",
"{resource}/{operation}/{id}",
new { controller = "Resource", action = "Index", resource = "", operation = "" id = "" }
);
and then you could parse out what the things are..
as a side note and if you were making more end points for your service, you might consider using GET, POST, PUT, DELETE instead of actually having "Insert" in the URI. REST.
Related Topics
Wordpress: Loading Multiple Scripts with Enqueue
Getting Multiple Checkboxes Names/Id's with PHP
Run a Ffmpeg Process in the Background
Strict Standards: Only Variables Should Be Assigned by Reference PHP 5.4
PHP File Upload Error Tmp_Name Is Empty
Get Variables from the Outside, Inside a Function in PHP
How to Convert Excel Xls to CSV Using PHP
Laravel - Database, Table and Column Naming Conventions
Laravel 5.2 Cors, Get Not Working with Preflight Options
How to Call a PHP Function from Ajax
How to Validate a Domain Name Using Regex & PHP
Return PHP Object by Index Number (Not Name)
Detecting a Url Using Preg_Match? Without Http:// in the String
Split a Text into Single Words