0

folks!

This is my first experience with big scripts in PHP CLI and I'm facing a 'not found' error when using the sqlsrv_connect function in my script. Running the script in the browser is okay, connects all fine, the queries goes as fine as it could; but when in the CLI, my friend, it shows

Fatal error: Call to undefined function sqlsrv_connect()

What could it be, dark magic or newbie developer?

This is how i use the function:

$_dbip = '127.0.0.1';
$_dbnome = $nome_bd;
$_dbuid = 'sa';
$_dbpwd = 'very_strong_secret_pwd';

$conn = sqlsrv_connect($_dbip, array('Database' => $_dbnome, 'UID' => $_dbuid, 'PWD' => $_dbpwd)) or die( print_r( sqlsrv_errors(), true));

Thanks in advance!

Ivan Cézanne
  • 78
  • 1
  • 11

2 Answers2

1

There are two php.ini files , one for the CLI and one for the Web browser.

You need to make sure the extension is enable on both.

You should use PDO if possible, because it is a better extension and it supports SQL server.

meda
  • 45,103
  • 14
  • 92
  • 122
0

Just realized that the PDO version of SQLSRV was the one activated. I really just got a single php.ini file and simply added a new line declaring the SQLSRV without the PDO.

Thanks for the help, still!

Ivan Cézanne
  • 78
  • 1
  • 11