Reputation: 1108
I'm getting the error
Fatal error: Uncaught Error: Call to undefined function odbc_connect()
Ive added the extension in php.ini and phpinfo() is confirming that the odbc driver exists (see screenshot)
the php script is just a simple query
<?php
$num_minutes = 10;
ini_set('max_execution_time', (60*$num_minutes));
$conn = odbc_connect("CData Sage50UK Source","manager","password");
$query = odbc_exec($conn, "SELECT * FROM SalesOrders LIMIT 1");
while($row = odbc_fetch_array($query)){
$json1[] = array_map('utf8_encode', $row);
}
echo json_encode($json1);
?>
Upvotes: 1
Views: 7803
Reputation: 168685
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)
Upvotes: 1