Linux – PHP 7.0 and MSSQL (Microsoft SQL)

Microsoft has PHP Linux Drivers for SQL Server for PHP 7 and above on PECL. These are production ready. To download them, follow these steps: Ubuntu 16.04: sudo su curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add – curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list exit sudo apt-get update sudo ACCEPT_EULA=Y apt-get install -y msodbcsql mssql-tools unixodbc-dev sudo pecl install sqlsrv … Read more

Need a row count after SELECT statement: what’s the optimal SQL approach?

If you’re using SQL Server, after your query you can select the @@RowCount function (or if your result set might have more than 2 billion rows use the RowCount_Big() function). This will return the number of rows selected by the previous statement or number of rows affected by an insert/update/delete statement. SELECT my_table.my_col FROM my_table … Read more

Check if a SQL table exists

bool exists; try { // ANSI SQL way. Works in PostgreSQL, MSSQL, MySQL. var cmd = new OdbcCommand( “select case when exists((select * from information_schema.tables where table_name=”” + tableName + “”)) then 1 else 0 end”); exists = (int)cmd.ExecuteScalar() == 1; } catch { try { // Other RDBMS. Graceful degradation exists = true; var … Read more

Creating a custom ODBC driver

Another option: Instead of creating a ODBC driver, implement a back end that talks the wire protocol that another database (Postgresql or MySQL for instance) uses. Your users can then download and use for instance the Postgresql ODBC driver. Exactly what back-end database you choose to emulate should probably depend the most on how well … Read more

Connecting to MS SQL Server with Windows Authentication using Python?

You can specify the connection string as one long string that uses semi-colons (;) as the argument separator. Working example: import pyodbc cnxn = pyodbc.connect(r’Driver=SQL Server;Server=.\SQLEXPRESS;Database=myDB;Trusted_Connection=yes;’) cursor = cnxn.cursor() cursor.execute(“SELECT LastName FROM myContacts”) while 1: row = cursor.fetchone() if not row: break print(row.LastName) cnxn.close() For connection strings with lots of parameters, the following will accomplish … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)