Call to Undefined Function Odbc_Connect() PHP 7

Call to undefined function odbc_connect() php 7

The DOC page does list PHP 7, so just install php-odbc and you should be good to go. Currently using it myself on RedHat EL7 with Remi php7.

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:

  1. 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.

  2. 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)

Call to undefined function odbc_connect() on Windows Server 2008

PHP offers two kinds of support for ODBC (and most database drivers):

  • Through PDO
  • Standalone

You have enabled the PDO version (php_pdo_odbc.dll), but you're trying to use a non-PDO function. You've got two options:

  • Enable the standalone functionality via php_odbc.dll (note the slightly different name)
  • Use ODBC via the PDO interface

PDO is

a lightweight, consistent interface for accessing databases in PHP

and I generally prefer it to the database-specific interfaces, but either should work.

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.

  1. 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.
  2. 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).
  3. Create an ODBC data source in /etc/odbc.ini that connects to the
    SQL 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

[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);
?>
  1. Replace data_source_name, database_username and database_password
    with your SQL Server ODBC data source, login name and password.
  2. 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
  3. 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.
  4. 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

Call to undefined function odbc_connect() in Ubuntu

Call to undefined function odbc_connect() means that your PHP system doesn't have any function with that name.

Since it isn't a user function written in pure PHP but a function from a PHP extension, that means that you haven't installed such extension. It's worth noting that the PHP extensions is not the same as the SQL Server driver (you need both).

Your code also contains some undefined constants which I guess are meant to be strings. I strongly recommend you enable full error reporting in your development box so you don't need to check the error logs to learn about simple errors.



Related Topics



Leave a reply



Submit